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

Improve capabilities of ion schema subcommands #159

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

popematt
Copy link
Contributor

@popematt popematt commented Oct 22, 2024

Issue #, if available:

Fix #33
Fix #38

Description of changes:

  • Added IonSchemaCommandInput that handles arguments for schemas and types
  • Added InputGrouping that accepts flags to determine how to enumerate through inputs. I separated this out because I also see it being useful for commands like ion hash.
  • Nearly a complete rewrite of ion schema validate to use the new options and to produce a simpler output.
  • Change ion schema load to ion schema check, which better describes its purpose. It also uses IonSchemaCommandInput now to handle the schema args.
  • Drive by fix to pin the version of ion-rs so that we don't have unexpected breakages in the future. (See Unable to install on Windows via cargo install ion-cli #155)
  • Start using the wrap_help feature of clap so that we don't have to wrap our help messages.

Here is the help message for ion schema validate. If you have any suggestions for the flag/option names, please speak up. I'd like to try to have fairly consistent/unified options across the various subcommands.

(UNSTABLE) Validates an Ion value based on a given Ion Schema type.

Usage: ion schema validate [OPTIONS] <type> [input]...

Arguments:
  <type>      An ISL type name or, if no schema is specified, an inline type definition.
  [input]...  Input file

Options:
  -L                      Interpret each line as a separate input.
  -T                      Interpret each top level value as a separate input.
  -o, --output <output>   Output file [default: STDOUT]
  -E, --error-on-invalid  Return a non-zero exit code when a value is invalid for the given type.
  -q, --quiet             Suppresses the violations output.
  -h, --help              Print help
  -V, --version           Print version

Selecting a schema:
      --empty <version>            An empty schema document for the specified Ion Schema version.
                                   [default: 2.0] [possible values: 1.0, 2.0]
  -f, --schema-file <schema-file>  A schema file
      --schema-text <schema-text>  The Ion text contents of a schema document.
      --id <schema-id>             The ID of a schema to load from one of the configured authorities.
  -A, --authority <directory>      The root(s) of the file system authority(s). Authorities are only
                                   required if your schema needs to import a type from another schema
                                   or if you are loading a schema using the --id option.

All Ion Schema types are defined in the context of a schema document, so it is necessary to always
have a schema document, even if that schema document is an implicit, empty schema. If a schema is not
specified, the default is an implicit, empty Ion Schema 2.0 document.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

clap = { version = "4.5.8", features = ["cargo", "env"] }
clap = { version = "4.5.8", features = ["cargo", "env","wrap_help"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 wrap_help is a great add, thanks!

@popematt popematt merged commit dd28ec6 into amazon-ion:main Oct 23, 2024
3 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
2 participants