Skip to content

Commit

Permalink
CLI: make the output of create commands machine-readable (#8833)
Browse files Browse the repository at this point in the history
The underlying SDK functions already emit human-friendly log messages
with the ID of the created resource. Instead of printing largely the
same message twice, we can just print the ID. That way, the CLI can be
more easily integrated into other software.
  • Loading branch information
SpecLad authored Dec 17, 2024
1 parent 4d26d5c commit 73458b3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions changelog.d/20241216_144316_roman_machine_readable_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Changed

- \[CLI\] The output of the `task create`, `task create-from-backup` and
`project create` commands is now just the created resource ID,
making it machine-readable
(<https://github.com/cvat-ai/cvat/pull/8833>)
2 changes: 1 addition & 1 deletion cvat-cli/src/cvat_cli/_internal/commands_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def execute(
dataset_format=dataset_format,
status_check_period=status_check_period,
)
print(f"Created project ID {project.id}")
print(project.id)


@COMMANDS.command_class("delete")
Expand Down
4 changes: 2 additions & 2 deletions cvat-cli/src/cvat_cli/_internal/commands_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def execute(
status_check_period=status_check_period,
pbar=DeferredTqdmProgressReporter(),
)
print("Created task id", task.id)
print(task.id)


@COMMANDS.command_class("delete")
Expand Down Expand Up @@ -406,7 +406,7 @@ def execute(self, client: Client, *, filename: str, status_check_period: int) ->
status_check_period=status_check_period,
pbar=DeferredTqdmProgressReporter(),
)
print(f"Created task ID", task.id)
print(task.id)


@COMMANDS.command_class("auto-annotate")
Expand Down
4 changes: 2 additions & 2 deletions tests/python/cli/test_cli_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_can_create_project(self):
"https://bugs.example/",
)

project_id = int(stdout.split()[-1])
project_id = int(stdout.rstrip("\n"))
created_project = self.client.projects.retrieve(project_id)
assert created_project.name == "new_project"
assert created_project.bug_tracker == "https://bugs.example/"
Expand All @@ -52,7 +52,7 @@ def test_can_create_project_from_dataset(self, fxt_coco_dataset):
"COCO 1.0",
)

project_id = int(stdout.split()[-1])
project_id = int(stdout.rstrip("\n"))
created_project = self.client.projects.retrieve(project_id)
assert created_project.name == "new_project"
assert {label.name for label in created_project.get_labels()} == {"car", "person"}
Expand Down
6 changes: 3 additions & 3 deletions tests/python/cli/test_cli_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_can_create_task_from_local_images(self):
"0.01",
)

task_id = int(stdout.split()[-1])
task_id = int(stdout.rstrip("\n"))
assert self.client.tasks.retrieve(task_id).size == 5

def test_can_create_task_from_local_images_with_parameters(self):
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_can_create_task_from_local_images_with_parameters(self):
"http://localhost/bug",
)

task_id = int(stdout.split()[-1])
task_id = int(stdout.rstrip("\n"))
task = self.client.tasks.retrieve(task_id)
frames = task.get_frames_info()
assert [f.name for f in frames] == [
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_can_upload_annotations(self, fxt_new_task: Task, fxt_coco_file: Path):
def test_can_create_from_backup(self, fxt_new_task: Task, fxt_backup_file: Path):
stdout = self.run_cli("task", "create-from-backup", str(fxt_backup_file))

task_id = int(stdout.split()[-1])
task_id = int(stdout.rstrip("\n"))
assert task_id
assert task_id != fxt_new_task.id
assert self.client.tasks.retrieve(task_id).size == fxt_new_task.size
Expand Down

0 comments on commit 73458b3

Please sign in to comment.