Commit da5d8e0
Add CLI parameters for cdf data respace plan/execute (#2522)
# Description
Add CLI parameters for `cdf data respace plan/execute`
Define Typer-annotated arguments and options for both subcommands:
- plan: csv_file (positional), --output-file/-o (default:
respace_plan.json)
- execute: plan_file (positional), --backup-dir/-b (required),
--dry-run/-d
Add RespaceMapping and RespaceMappingList data classes for future CSV
input parsing (columns: sourceSpace, externalId, targetSpace). External
ID is preserved — only the space changes. These classes are not yet
wired into the command logic.
## Bump
- [ ] Patch
- [x] Skip
## Changelog
### Changed
- cognite_toolkit/_cdf_tk/apps/_respace_app.py
What changed: The respace_plan() and respace_execute() methods
previously had no parameters. They now have full Typer-annotated CLI
parameter definitions:
- `respace_plan()`
Added two parameters:
- `csv_file`: required positional argument pointing to an existing CSV
file. Typer validates that the file exists, is a file (not a directory),
and resolves it to an absolute path. Help text documents the expected
columns: sourceSpace, externalId, targetSpace.
- `output_file`: optional named option (--output-file / -o) defaulting
to respace_plan.json in the current working directory.
Both parameters are forwarded to `RespaceCommand.plan()`.
- `respace_execute()`
Added three parameters:
- `plan_file`: required positional argument pointing to an existing JSON
plan file, with the same path validation as `csv_file`.
- `backup_dir`: required named option (--backup-dir / -b). No exists
check since the user might pass a directory that doesn't exist yet. The
execute command would create it during execution.
- `dry_run`: optional boolean flag (--dry-run / -d) defaulting to False.
All three parameters are forwarded to `RespaceCommand.execute()`.
- cognite_toolkit/_cdf_tk/commands/_respace.py
What changed: Two additions: the command methods now accept parameters,
and two new data classes were added for future CSV parsing.
- `RespaceMapping`: A new Pydantic model representing a single row of
the input CSV. It has three required string fields (source_space,
external_id, target_space) with alias_generator=to_camel_case so
camelCase CSV headers (sourceSpace, externalId, targetSpace) map to
snake_case fields. A `model_validator` rejects rows where sourceSpace ==
targetSpace. The external ID is preserved — only the space changes.
- `RespaceMappingList`: A ModelList[RespaceMapping] subclass that
provides CSV schema validation and parsing via the inherited
`read_csv_file()` method. Only implements the required abstract method
`_get_base_model_cls()`. Not yet wired into the command logic.
- `RespaceCommand.plan()`: Signature changed from plan(self) to
plan(self, csv_file: Path, output_file: Path). Prints the received
parameters as confirmation before the placeholder message.
- `RespaceCommand.execute()`: Signature changed from execute(self) to
execute(self, plan_file: Path, backup_dir: Path, dry_run: bool = False).
Prints the received parameters, using the verb-swapping pattern ("Would
execute" / "Executing") to indicate dry run mode, consistent with the
existing codebase style.
---------
Co-authored-by: Iván Surif <ivan.surif@cognite.com>1 parent 5ab8f8c commit da5d8e0
2 files changed
Lines changed: 92 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
24 | 44 | | |
25 | 45 | | |
26 | | - | |
| 46 | + | |
27 | 47 | | |
28 | 48 | | |
29 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
30 | 77 | | |
31 | 78 | | |
32 | | - | |
| 79 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
8 | 41 | | |
9 | 42 | | |
10 | 43 | | |
| |||
15 | 48 | | |
16 | 49 | | |
17 | 50 | | |
18 | | - | |
| 51 | + | |
19 | 52 | | |
| 53 | + | |
| 54 | + | |
20 | 55 | | |
21 | 56 | | |
22 | | - | |
| 57 | + | |
23 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
24 | 62 | | |
0 commit comments