Skip to content

Commit bf1fed4

Browse files
authored
Improved DataFrameOutputFormatter (#341)
* refactor DataFrameOutputFormatter to enable checkpointing * organize and fix json extra newline at end * fix tests * whitespace * add tuple to ensure_iterable * rm test file * missing s * output real unicode in json * move kwargs default out of loop * refactor duplicated option definitions * define column option * DF formatter improvements * switch securitydata to use DFOutputFormatter everywhere * add/improve docstrings * fix output_format tests * test iterrows * default FileEventsOutputFormatter to RAW * handle when checkpoint key isn't in columns selected * add notes back to saved-search list * fix test_securitydata * add test for checkpointing when column missing * rm df.html * style * fix null handling in newer pandas versions * fix table format tests for differing pandas versions * max tox pandas requires match pkg * Auto print "No results found" from echo_formatted_dataframes * style and changelog * add test for echo-ing "No results found." on emtpy df * remove uneeded check for empty df * rm check for empty dfs in user cmds * elif
1 parent e08765c commit bf1fed4

16 files changed

Lines changed: 537 additions & 354 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1010

1111
## 1.11.1 - 2021-11-09
1212

13+
### Added
14+
- `--columns` option to `security-data search` and `security-data send-to` commands which reduces output to only the specified colums/json keys. Accepts a comma-separated list of column names (case-insensitive).
15+
1316
### Changed
14-
- Updated minimum version of py42 to `1.19.3` to provide access to updated URI paths for new standardized versioning scheme
17+
- Updated minimum version of py42 to `1.19.3` to provide access to updated URI paths for new standardized versioning scheme.
18+
- Improved accuracy of checkpointing for `security-data search` (checkpoints every row as it is printed to stdout instead of just the last event of the search response).
1519

1620
## 1.11.0 - 2021-10-22
1721

src/code42cli/cmds/alerts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
from code42cli.cmds.util import try_get_default_header
2222
from code42cli.date_helper import convert_datetime_to_timestamp
2323
from code42cli.date_helper import limit_date_range
24+
from code42cli.enums import JsonOutputFormat
25+
from code42cli.enums import OutputFormat
2426
from code42cli.file_readers import read_csv_arg
2527
from code42cli.options import format_option
26-
from code42cli.output_formats import JsonOutputFormat
27-
from code42cli.output_formats import OutputFormat
2828
from code42cli.output_formats import OutputFormatter
2929
from code42cli.util import hash_event
3030
from code42cli.util import parse_timestamp

src/code42cli/cmds/devices.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,8 @@ def list_devices(
357357
df = _add_usernames_to_device_dataframe(state.sdk, df)
358358
if include_legal_hold_membership:
359359
df = _add_legal_hold_membership_to_device_dataframe(state.sdk, df)
360-
if df.empty:
361-
click.echo("No results found.")
362-
else:
363-
formatter = DataFrameOutputFormatter(format)
364-
formatter.echo_formatted_dataframe(df)
360+
formatter = DataFrameOutputFormatter(format)
361+
formatter.echo_formatted_dataframes(df)
365362

366363

367364
def _add_legal_hold_membership_to_device_dataframe(sdk, df):
@@ -493,11 +490,8 @@ def list_backup_sets(
493490
if include_usernames:
494491
df = _add_usernames_to_device_dataframe(state.sdk, df)
495492
df = _add_backup_set_settings_to_dataframe(state.sdk, df)
496-
if df.empty:
497-
click.echo("No results found.")
498-
else:
499-
formatter = DataFrameOutputFormatter(format)
500-
formatter.echo_formatted_dataframe(df)
493+
formatter = DataFrameOutputFormatter(format)
494+
formatter.echo_formatted_dataframes(df)
501495

502496

503497
def _add_backup_set_settings_to_dataframe(sdk, devices_dataframe):

src/code42cli/cmds/search/options.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from code42cli.click_ext.options import incompatible_with
88
from code42cli.click_ext.types import FileOrString
9+
from code42cli.enums import SendToFileEventsOutputFormat
910
from code42cli.logger.enums import ServerProtocol
10-
from code42cli.output_formats import SendToFileEventsOutputFormat
1111

1212

1313
def is_in_filter(filter_cls):
@@ -143,6 +143,22 @@ def advanced_query_option(term, **kwargs):
143143
return click.option("--advanced-query", **defaults)
144144

145145

146+
or_query_option = click.option(
147+
"--or-query",
148+
is_flag=True,
149+
cls=AdvancedQueryAndSavedSearchIncompatible,
150+
help="Combine query filter options with 'OR' logic instead of the default 'AND'.",
151+
)
152+
153+
include_all_option = click.option(
154+
"--include-all",
155+
default=False,
156+
is_flag=True,
157+
help="Display simple properties of the primary level of the nested response.",
158+
cls=incompatible_with("columns"),
159+
)
160+
161+
146162
def server_options(f):
147163
hostname_arg = click.argument("hostname")
148164
protocol_option = click.option(

0 commit comments

Comments
 (0)