Skip to content

Commit 6dc5c40

Browse files
author
Juliya Smith
authored
JSON output format and other fixes (#217)
1 parent 6cf1280 commit 6dc5c40

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

src/code42cli/cmds/cases.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
from pprint import pformat
43

54
import click
65
from py42.clients.cases import CaseStatus
@@ -20,20 +19,23 @@
2019
case_number_option = click.option(
2120
"--case-number", type=int, help="The number assigned to the case.", required=True
2221
)
23-
name_option = click.option("--name", help="Name of the case.",)
24-
assignee_option = click.option("--assignee", help="User UID of the assignee.")
25-
description_option = click.option("--description", help="Description of the case.")
26-
findings_option = click.option("--findings", help="Findings on the case.")
27-
subject_option = click.option("--subject", help="User UID of a subject of the case.")
22+
name_option = click.option("--name", help="The name of the case.",)
23+
assignee_option = click.option(
24+
"--assignee", help="The UID of the user to assign to the case."
25+
)
26+
description_option = click.option("--description", help="The description of the case.")
27+
findings_option = click.option("--findings", help="Any findings for the case.")
28+
subject_option = click.option(
29+
"--subject", help="The user UID of the subject of the case."
30+
)
2831
status_option = click.option(
2932
"--status",
3033
help="Status of the case. `OPEN` or `CLOSED`.",
3134
type=click.Choice(CaseStatus.choices()),
3235
)
3336
file_event_id_option = click.option(
34-
"--event-id", required=True, help="File event id associated to the case."
37+
"--event-id", required=True, help="The file event ID associated with the case."
3538
)
36-
3739
CASES_KEYWORD = "cases"
3840
BEGIN_DATE_DICT = set_begin_default_dict(CASES_KEYWORD)
3941
END_DATE_DICT = set_end_default_dict(CASES_KEYWORD)
@@ -110,10 +112,10 @@ def update(state, case_number, name, subject, assignee, description, findings, s
110112

111113
@cases.command("list")
112114
@click.option(
113-
"--name", help="Filter by name of a case, supports partial name matches.",
115+
"--name", help="Filter by name of a case. Supports partial name matches.",
114116
)
115-
@click.option("--subject", help="Filter by user UID of the subject of a case.")
116-
@click.option("--assignee", help="Filter by user UID of assignee.")
117+
@click.option("--subject", help="Filter by the user UID of the subject of a case.")
118+
@click.option("--assignee", help="Filter by the user UID of an assignee.")
117119
@click.option("--begin-create-time", **BEGIN_DATE_DICT)
118120
@click.option("--end-create-time", **END_DATE_DICT)
119121
@click.option("--begin-update-time", **BEGIN_DATE_DICT)
@@ -162,7 +164,7 @@ def _get_file_events(sdk, case_number):
162164
def _display_file_events(events):
163165
if events:
164166
click.echo("\nFile Events:\n")
165-
click.echo(pformat(events))
167+
click.echo(json.dumps(events, indent=4))
166168
else:
167169
click.echo("\nNo events found.")
168170

@@ -190,7 +192,9 @@ def show(state, case_number, format, include_file_events):
190192
@cases.command()
191193
@case_number_arg
192194
@click.option(
193-
"--path", help="File path. Defaults to the current directory.", default="."
195+
"--path",
196+
help="The file path where to save the PDF. Defaults to the current directory.",
197+
default=os.getcwd(),
194198
)
195199
@sdk_options()
196200
def export(state, case_number, path):

src/code42cli/cmds/devices.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ def devices(state):
3333
"device-guid", type=str, callback=lambda ctx, param, arg: _verify_guid_type(arg),
3434
)
3535

36-
change_device_name_option = click.option(
37-
"--change-device-name",
38-
required=False,
39-
is_flag=True,
40-
default=False,
41-
help="Prepend 'deactivated_<current_date>' to the name of any deactivated devices.",
42-
)
36+
37+
def change_device_name_option(help_msg):
38+
return click.option(
39+
"--change-device-name",
40+
required=False,
41+
is_flag=True,
42+
default=False,
43+
help=help_msg,
44+
)
45+
4346

4447
DATE_FORMAT = "%Y-%m-%d"
4548
purge_date_option = click.option(
@@ -54,7 +57,9 @@ def devices(state):
5457

5558
@devices.command()
5659
@device_guid_argument
57-
@change_device_name_option
60+
@change_device_name_option(
61+
"Prepend 'deactivated_<current_date>' to the name of the device if deactivation is successful."
62+
)
5863
@purge_date_option
5964
@sdk_options()
6065
def deactivate(state, device_guid, change_device_name, purge_date):
@@ -479,7 +484,9 @@ def bulk(state):
479484

480485
@bulk.command(name="deactivate")
481486
@read_csv_arg(headers=_bulk_device_activation_headers)
482-
@change_device_name_option
487+
@change_device_name_option(
488+
"Prepend 'deactivated_<current_date>' to the name of any successfully deactivated devices."
489+
)
483490
@purge_date_option
484491
@format_option
485492
@sdk_options()

tests/cmds/test_cases.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
from unittest import mock
34
from unittest.mock import mock_open
45

@@ -227,7 +228,8 @@ def test_export_calls_export_summary_with_expected_params(runner, cli_state, moc
227228
cli, ["cases", "export", "1"], obj=cli_state,
228229
)
229230
cli_state.sdk.cases.export_summary.assert_called_once_with(1)
230-
mf.assert_called_once_with("./1_case_summary.pdf", "wb")
231+
expected = os.path.join(os.getcwd(), "1_case_summary.pdf")
232+
mf.assert_called_once_with(expected, "wb")
231233

232234

233235
def test_export_when_missing_case_number_prints_error(runner, cli_state):

0 commit comments

Comments
 (0)