Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(names) add --format option #4778

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

DanielDewberry
Copy link
Contributor

Add --format option to snapcraft names to enable output format selection. Possible choices are:

  • table (default, existing behaviour)
  • json

tests/unit/commands/test_names.py:

  • Add test class TestNames.

  • Rename test_names to test_table and move it into the scope of TestName. Add format to argparse.Namespace.

  • Add test_json to TestNames.

  • Have you followed the guidelines for contributing?

  • Have you signed the CLA?

  • Have you successfully run tox run -m lint?

  • Have you successfully run tox run -e test-py310? (supported versions: py39, py310, py311, py312)


The motivation for adding JSON formatted output to the names sub-command, is that of data pipelines. It will enable tooling to read the command output and leverage JSON parsers rather than performing text processing. A small quality of life improvement :)
The JSON structure leaves room for extension if subsequently required:

{
    "snaps": [
        {
            "name": "test-snap-private",
            "since": "2016-07-26T20:18:32Z",
            "visibility": "private",
            "notes": "-",
        },
    ]
}

@DanielDewberry
Copy link
Contributor Author

DanielDewberry commented Apr 30, 2024

I added the email address on the commits to Launchpad several hours ago in the hope that the CLA check would validate correctly...

Update: I have subsequently signed the CLA again to see if the database will store it now that the email address is in Launchpad

Copy link
Collaborator

@mr-cal mr-cal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks for another contribution!

snapcraft/commands/names.py Show resolved Hide resolved
@mr-cal mr-cal requested review from tigarmo and lengau May 9, 2024 15:43
Copy link
Contributor

@lengau lengau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks fairly similar to how Charmcraft does this, but with some improvements I'll probably be copying over :-)

@lengau lengau self-requested a review May 9, 2024 17:42
@lengau
Copy link
Contributor

lengau commented May 9, 2024

@DanielDewberry if you have opinions on a general case for this on more commands (e.g. list-tracks), I'd love to hear them in this feature request.

@DanielDewberry
Copy link
Contributor Author

Thanks! This looks fairly similar to how Charmcraft does this, but with some improvements I'll probably be copying over :-)

Thank you, that's a compliment and a half :)

Add --format option to snapcraft names to enable output format
selection. Possible choices are:
- table (default, existing behaviour)
- json (pretty print with 4sp indent)

tests/unit/commands/test_names.py:
- Add test class TestNames.
- Rename test_names to test_table and move it into the scope of
  TestName. Add format to argparse.Namespace.
- Add test_json to TestNames.
- Add test_format_error to TestNames.
@mr-cal mr-cal enabled auto-merge (squash) May 31, 2024 20:35
@mr-cal mr-cal disabled auto-merge June 3, 2024 19:30
@mr-cal mr-cal merged commit 42046b5 into canonical:main Jun 3, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants