c2patool icon indicating copy to clipboard operation
c2patool copied to clipboard

Experimental subcommand-based interface

Open ok-nick opened this issue 1 year ago • 2 comments

Changes in this pull request

Rework the CLI to use subcommands rather than optional arguments.

  • Introduces subcommands as follows
    • c2patool sign - sign manifest
    • c2patool extract - extract data
      • c2patool extract resources - extract resources
      • c2patool extract ingredient - extract ingredient json and binary manifest
      • c2patool extract manifest - extract json manifest (can extract .c2pa manifest with --binary )
    • c2patool view - view info about manifest
      • c2patool view manifest - view user-friendly json manifest (can specify --debug)
      • c2patool view ingredient - view json ingredient
      • c2patool view info - view general info about a manifest
      • c2patool view tree - view manifest tree
      • c2patool view certs - view manifest certs
  • More intuitive
    • With the old one, it's valid to specify c2patool i.jpg --info --certs --tree --detailed --manifest manifest.json --output o.jpg trust, but what's actually happening?
    • With the new one, it's impossible to make an ambiguous call, for each subcommand you can only specify the arguments relevant to that subcommand (otherwise clap will output a user-friendly error w/ suggestions)
    • Because of this, --help menus are much shorter and navigable, describing what subcommands/args are valid to specify
    • Subcommands also follow a familiar interface, similar to existing tools such as cargo, rustup, cross, git, etc.
  • Easier to modularize
    • Subcommands can be broken down into logical units, making it significantly easier to add new subcommands and modify existing ones
    • Subcommands can be constructed individually and tested individually
  • Migrated to the (new) c2pa-rs unstable API
    • #187

Additional Changes

  • Added insta-rs snapshot integration tests (asserts outputs against a reference value)
  • Added --binary flag to extract manifest as .c2pa binary manifest
  • Added --no-verify flag to allow extracting invalid binary manifests for debugging
  • Added --unknown flag to additionally extract unstandardized labeled resources
  • Added --no-embed flag when signing to not embed a manifest in the asset.
  • Added glob as input path to sign multiple assets w/ the same manifest
  • Added --verbose flag to specify verbosity via flags (rather than only env vars)
  • Changed args to kebab-case (default) rather than a mix of kebab-case and snake_case
  • Changed --no-verify-signing to --no-verify
  • Changed check to allow different file extensions for input/output if --sidecar is specified
  • Changed ingredient_paths to be merged into ingredients field, specifying path or inline ingredient in .json
  • Changed --remote to --manifest-url and applied the same suffix-style pattern to trust args
  • Removed extracting ingredient .json also extracts .c2pa binary manifest (use extract manifest --binary)
  • ~~Removed --remote in favor of specifying path or url in --manifest (similar to trust args)~~

Uncertain Changes

  • Removed checking for child ingredient.json if directory specified as ingredient path
  • Removed passing manifest as string via --config
  • Removed displaying manifest after signing (what would happen if multiple files are signed?)

Examples

# old
c2patool some_dir/C.jpg
# new - exactly the same
c2patool some_dir/C.jpg
# new - the above command redirects to below
c2patool view manifest some_dir/C.jpg
# new - let's view a detailed (debug) manifest
c2patool view manifest some_dir/C.jpg --debug

# old - let's view the certs
c2patool some_dir/C.jpg --certs
# new - the view subcommand contains: manifest, ingredient, info, tree, certs
c2patool view certs some_dir/C.jpg

# old - let's sign a manifest
c2patool some_dir/C.jpg --manifest some_dir/ingredient_test.json --output some_dir/C-signed.jpg
# new - very similar, it's now locked behind a subcommand
c2patool sign some_dir/C.jpg --manifest some_dir/ingredient_test.json --output some_dir/C-signed.jpg
# new - let's sign jpg files recursively
c2patool sign some_dir/**/*.jpg --manifest some_dir/ingredient_test.json --output some_dir/

# old - let's extract resources
c2patool some_dir/C.jpg --output some_dir
# new - now our intention is clear
c2patool extract resources some_dir/C.jpg --output some_dir
# new - I want to extract resources for all jpg files in some_dir
c2patool extract resources some_dir/*.jpg --output some_dir

Screenshots

c2patool
c2patool extract
c2patool view
c2patool view manifest -h
c2patool sign -h

Checklist

  • [ ] This PR represents a single feature, fix, or change.
  • [ ] All applicable changes have been documented.
  • [ ] Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

ok-nick avatar Jun 06 '24 20:06 ok-nick

Codecov Report

Attention: Patch coverage is 68.40077% with 164 lines in your changes missing coverage. Please review.

Project coverage is 74.43%. Comparing base (f216d3e) to head (e4e0553). Report is 1 commits behind head on main.

Files Patch % Lines
src/commands/sign.rs 66.84% 63 Missing :warning:
src/commands/extract.rs 60.37% 42 Missing :warning:
src/commands/view.rs 63.72% 37 Missing :warning:
src/main.rs 62.50% 15 Missing :warning:
src/commands/mod.rs 88.13% 7 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #185       +/-   ##
===========================================
+ Coverage   47.89%   74.43%   +26.53%     
===========================================
  Files           4        7        +3     
  Lines         666      841      +175     
===========================================
+ Hits          319      626      +307     
+ Misses        347      215      -132     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Jun 06 '24 20:06 codecov-commenter

Nice job

mauricefisher64 avatar Jun 07 '24 20:06 mauricefisher64

Closing now that we're moving to c2pa-rs repo.

This work is carried forward in contentauth/c2pa-rs#729.

scouten-adobe avatar Dec 11 '24 00:12 scouten-adobe