From e60f854959216b4dede1dcc1fa72c0ac4cd0e3a6 Mon Sep 17 00:00:00 2001 From: Khushboo Desai Date: Fri, 1 Nov 2024 11:27:41 -0700 Subject: [PATCH 1/3] Adds README changes --- README.md | 10 +++------- code-gen-projects/README.md | 13 +++++-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index aba2297..eafee37 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # `ion-cli` + [![Crate](https://img.shields.io/crates/v/ion-cli.svg)](https://crates.io/crates/ion-cli) [![License](https://img.shields.io/hexpm/l/plug.svg)](https://github.com/amazon-ion/ion-cli/blob/main/LICENSE) [![CI Build](https://github.com/amazon-ion/ion-cli/workflows/CI%20Build/badge.svg)](https://github.com/amazon-ion/ion-cli/actions?query=workflow%3A%22CI+Build%22) @@ -11,7 +12,8 @@ for working with [the Ion data format](https://amzn.github.io/ion-docs/docs/spec * [Examples](#examples) * [Viewing the contents of an Ion file](#viewing-the-contents-of-an-ion-file) * [Converting between Ion formats](#converting-between-ion-formats) - * [Converting between Ion and other formats with `to` and `from`](#converting-between-ion-and-other-formats-with-to-and-from) + * [Converting between Ion and other formats with `to` and + `from`](#converting-between-ion-and-other-formats-with-to-and-from) * [Analyzing binary Ion file encodings with `inspect`](#analyzing-binary-ion-file-encodings-with-inspect) * [Installation](#installation) * [via `brew`](#via-brew) @@ -185,12 +187,6 @@ subcommand) of `ion-cli`, run: brew install ion-cli --HEAD ``` -If you are looking into accessing all features with `cargo` (including `experimental` features) of `ion-cli`, run: - -```shell -cargo install ion-cli --all-features -``` - Then make sure that `~/.cargo/bin` is on your `$PATH`. You can confirm that it has been installed successfully by running: diff --git a/code-gen-projects/README.md b/code-gen-projects/README.md index 9ae206b..0f7db4f 100644 --- a/code-gen-projects/README.md +++ b/code-gen-projects/README.md @@ -83,9 +83,6 @@ tasks { } ``` -_Note: Code generation subcommand `generate` is under a feature flag. It is available -through `brew install ion-cli --HEAD` or `cargo install ion-cli --all-features`._ - ### Tests The tests for the generated code are defined in `CodeGenTests.java`. It has the following tests: @@ -101,12 +98,12 @@ The tests for the generated code are defined in `CodeGenTests.java`. It has the Here are the steps to follow for running tests: -1. Install ion-cli with either `brew install ion-cli --HEAD` or `cargo install ion-cli --all-features`. +1. Install ion-cli with either `brew install ion-cli` or `cargo install ion-cli`. 1. If you installed with brew then your executable is there in `ion` and you don't need to set up `ION_CLI` environment variable. 2. If you installed with `cargo` then your executable would be in `$HOME/.cargo/bin` and you need to setup the environment variable `ION_CLI` to point to the executable's path. If you need latest commits from cargo which are - not released yet, then do `cargo install ion-cli --all-features --git https://github.com/amazon-ion/ion-cli.git`. + not released yet, then do `cargo install ion-cli --git https://github.com/amazon-ion/ion-cli.git`. 2. All the tests uses an environment variable `ION_INPUT` which has the path to input Ion files. So if you want to test out this project locally set the environment variable `ION_INPUT` to point to `code-gen-projects/input.`_ 3. `cd code-gen-projects/java/code-gen-demo` @@ -178,7 +175,7 @@ fn main() { ``` _Note: Code generation subcommand `generate` is under a feature flag. It is available -through `brew install ion-cli --HEAD` or `cargo install ion-cli --all-features`._ +through `brew install ion-cli` or `cargo install ion-cli`._ ### Tests @@ -194,12 +191,12 @@ The tests for the generated code are defined in `tests` module in `lib.rs`. It h Here are the steps to follow for running tests: -1. Install ion-cli with either `brew install ion-cli --HEAD` or `cargo install ion-cli --all-features`. +1. Install ion-cli with either `brew install ion-cli` or `cargo install ion-cli`. 1. If you installed with brew then your executable is there in `ion` and you need to setup the environment variable `ION_CLI` to point to the executable's path. 2. If you installed with `cargo` then your executable would be in `$HOME/.cargo/bin` and you need to setup the environment variable `ION_CLI` to point to the executable's path. If you need latest commits from cargo which are - not released yet, then do `cargo install ion-cli --all-features --git https://github.com/amazon-ion/ion-cli.git`. + not released yet, then do `cargo install ion-cli --git https://github.com/amazon-ion/ion-cli.git`. 2. `cd code-gen-projects/rust/code-gen-demo` 3. Finally, to run the tests, just do: From 23373d7da7def5c0a9ab09d92f5997b78a0f8905 Mon Sep 17 00:00:00 2001 From: Khushboo Desai Date: Fri, 1 Nov 2024 14:18:12 -0700 Subject: [PATCH 2/3] Adds changes for generate subcommand options --- .../java/code-gen-demo/build.gradle.kts | 2 +- code-gen-projects/rust/code-gen-demo/build.rs | 2 +- src/bin/ion/commands/generate/mod.rs | 37 +++++++++++-------- tests/cli.rs | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/code-gen-projects/java/code-gen-demo/build.gradle.kts b/code-gen-projects/java/code-gen-demo/build.gradle.kts index ca742d3..55dc37d 100644 --- a/code-gen-projects/java/code-gen-demo/build.gradle.kts +++ b/code-gen-projects/java/code-gen-demo/build.gradle.kts @@ -44,7 +44,7 @@ tasks { "-X", "generate", "-l", "java", "-n", "org.example", - "-d", ionSchemaSourceCodeDir, + "-A", ionSchemaSourceCodeDir, "-o", generatedIonSchemaModelDir, ) .workingDir(rootProject.projectDir) diff --git a/code-gen-projects/rust/code-gen-demo/build.rs b/code-gen-projects/rust/code-gen-demo/build.rs index 47b0a7f..6c355dd 100644 --- a/code-gen-projects/rust/code-gen-demo/build.rs +++ b/code-gen-projects/rust/code-gen-demo/build.rs @@ -16,7 +16,7 @@ fn main() { .arg("generate") .arg("-l") .arg("rust") - .arg("-d") + .arg("-A") .arg(format!("{}/../../schema", crate_dir)) .arg("-o") .arg(&out_dir); diff --git a/src/bin/ion/commands/generate/mod.rs b/src/bin/ion/commands/generate/mod.rs index 48fec8e..f7ce9ed 100644 --- a/src/bin/ion/commands/generate/mod.rs +++ b/src/bin/ion/commands/generate/mod.rs @@ -11,7 +11,7 @@ use crate::commands::generate::model::NamespaceNode; use crate::commands::generate::utils::{JavaLanguage, RustLanguage}; use crate::commands::IonCliCommand; use anyhow::{bail, Result}; -use clap::{Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint}; use colored::Colorize; use ion_schema::authority::{DocumentAuthority, FileSystemDocumentAuthority}; use ion_schema::system::SchemaSystem; @@ -38,6 +38,8 @@ impl IonCliCommand for GenerateCommand { } fn configure_args(&self, command: Command) -> Command { + let schema_options_header = "Selecting a schema"; + command .arg( Arg::new("output") @@ -62,15 +64,19 @@ impl IonCliCommand for GenerateCommand { .help("Programming language for the generated code"), ) .arg( - // Directory(s) that will be used as authority(s) for schema system - Arg::new("directory") - .long("directory") - .short('d') - // If this appears more than once, collect all values + Arg::new("authority") + .help_heading(schema_options_header) + .long("authority") + .short('A') + .required(false) .action(ArgAction::Append) - .value_name("DIRECTORY") - .required(true) - .help("One or more directories that will be searched for the requested schema"), + .value_name("directory") + .value_hint(ValueHint::DirPath) + .help( + "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.", + ), ) } @@ -91,16 +97,15 @@ impl IonCliCommand for GenerateCommand { let output = binding.as_path(); // Extract the user provided document authorities/ directories - let authorities: Vec<&String> = args.get_many("directory").unwrap().collect(); + let authorities: Vec<&String> = args.get_many("authority").unwrap().collect(); // Set up document authorities vector let mut document_authorities: Vec> = vec![]; - - for authority in &authorities { - document_authorities.push(Box::new(FileSystemDocumentAuthority::new(Path::new( - authority, - )))) - } + args.get_many::("authority") + .unwrap_or_default() + .map(Path::new) + .map(FileSystemDocumentAuthority::new) + .for_each(|a| document_authorities.push(Box::new(a))); // Create a new schema system from given document authorities let mut schema_system = SchemaSystem::new(document_authorities); diff --git a/tests/cli.rs b/tests/cli.rs index 0c1a3f8..78966a6 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -272,7 +272,7 @@ mod code_gen_tests { "java", "--namespace", "org.example", - "--directory", + "--authority", temp_dir.path().to_str().unwrap(), ]); let command_assert = cmd.assert(); From 75caf30a109e700043c6bfedaf23824308e060c0 Mon Sep 17 00:00:00 2001 From: Khushboo Desai Date: Mon, 4 Nov 2024 08:55:41 -0800 Subject: [PATCH 3/3] Adds suggested changes --- code-gen-projects/README.md | 6 ++---- src/bin/ion/commands/generate/mod.rs | 5 +---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/code-gen-projects/README.md b/code-gen-projects/README.md index 0f7db4f..8a10304 100644 --- a/code-gen-projects/README.md +++ b/code-gen-projects/README.md @@ -103,7 +103,8 @@ Here are the steps to follow for running tests: environment variable. 2. If you installed with `cargo` then your executable would be in `$HOME/.cargo/bin` and you need to setup the environment variable `ION_CLI` to point to the executable's path. If you need latest commits from cargo which are - not released yet, then do `cargo install ion-cli --git https://github.com/amazon-ion/ion-cli.git`. + not released yet, then do `cargo install ion-cli --git https://github.com/amazon-ion/ion-cli.git` or + `brew install ion-cli --HEAD`. 2. All the tests uses an environment variable `ION_INPUT` which has the path to input Ion files. So if you want to test out this project locally set the environment variable `ION_INPUT` to point to `code-gen-projects/input.`_ 3. `cd code-gen-projects/java/code-gen-demo` @@ -174,9 +175,6 @@ fn main() { } ``` -_Note: Code generation subcommand `generate` is under a feature flag. It is available -through `brew install ion-cli` or `cargo install ion-cli`._ - ### Tests The tests for the generated code are defined in `tests` module in `lib.rs`. It has the following tests: diff --git a/src/bin/ion/commands/generate/mod.rs b/src/bin/ion/commands/generate/mod.rs index f7ce9ed..4b0adba 100644 --- a/src/bin/ion/commands/generate/mod.rs +++ b/src/bin/ion/commands/generate/mod.rs @@ -38,8 +38,6 @@ impl IonCliCommand for GenerateCommand { } fn configure_args(&self, command: Command) -> Command { - let schema_options_header = "Selecting a schema"; - command .arg( Arg::new("output") @@ -65,10 +63,9 @@ impl IonCliCommand for GenerateCommand { ) .arg( Arg::new("authority") - .help_heading(schema_options_header) .long("authority") .short('A') - .required(false) + .required(true) .action(ArgAction::Append) .value_name("directory") .value_hint(ValueHint::DirPath)