canonical / canonical/craft-application
Utility to allow a `format` option for commands.
- Dominant language
- Python
- Stars
- 14
- Forks
- 29
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 12
Description
### What needs to get done
Add utilities of some form to make it easy for commands to add a unified `format` option for various tabular command outputs.
Ideally a command's `fill_parser` method would be able to do something like:
```
utils.add_format_argument(parser)
```
and then we'd have a related function that actually emits the formatted message, something like:
```
def emit_formatted_output(format: FormatValue, headers: Sequence[str], data) -> None:
...
```
Here the `data` object would need to be something that can (at minimum) be used by [tabulate](https://pypi.org/project/tabulate/) and be serialised into JSON. With those two formats, we'd likely get the ability to do other formats (e.g. YAML, toml) if we decide to add that in the future.
### Why it needs to get done
This got added to the `names` command in snapcraft recently: https://github.com/canonical/snapcraft/pull/4778
Charmcraft has a [partial implementation](https://github.com/canonical/charmcraft/blob/e2ad204f828a4ef387090d3e626f0f6db34e5996/charmcraft/application/commands/base.py#L33), but still relies on the command itself being aware of each format.
Contributor guide
Research direction
Start by reviewing charmcraft/application/commands/base.py and the linked Snapcraft names implementation to understand the existing format handling. Define the shared command argument and output utility boundaries, including tabulate-compatible and JSON-serialisable data, then verify that commands can use the utilities without format-specific logic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100