c2patool
c2patool copied to clipboard
Experimental subcommand-based interface
Changes in this pull request
Rework the CLI to use subcommands rather than optional arguments.
- Introduces subcommands as follows
c2patool sign- sign manifestc2patool extract- extract datac2patool extract resources- extract resourcesc2patool extract ingredient- extract ingredient json and binary manifestc2patool extract manifest- extract json manifest (can extract .c2pa manifest with--binary)
c2patool view- view info about manifestc2patool view manifest- view user-friendly json manifest (can specify--debug)c2patool view ingredient- view json ingredientc2patool view info- view general info about a manifestc2patool view tree- view manifest treec2patool 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
clapwill output a user-friendly error w/ suggestions) - Because of this,
--helpmenus 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.
- With the old one, it's valid to specify
- 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
--binaryflag to extract manifest as .c2pa binary manifest - Added
--no-verifyflag to allow extracting invalid binary manifests for debugging - Added
--unknownflag to additionally extract unstandardized labeled resources - Added
--no-embedflag when signing to not embed a manifest in the asset. - Added glob as input path to sign multiple assets w/ the same manifest
- Added
--verboseflag 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-signingto--no-verify - Changed check to allow different file extensions for input/output if
--sidecaris specified - Changed
ingredient_pathsto be merged intoingredientsfield, specifying path or inline ingredient in .json - Changed
--remoteto--manifest-urland applied the same suffix-style pattern to trust args - Removed extracting ingredient .json also extracts .c2pa binary manifest (use
extract manifest --binary) - ~~Removed
--remotein favor of specifying path or url in--manifest(similar to trust args)~~
Uncertain Changes
- Removed checking for child
ingredient.jsonif 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 DOitems (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.
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.
Nice job
Closing now that we're moving to c2pa-rs repo.
This work is carried forward in contentauth/c2pa-rs#729.