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

Adds som README and CLI option changes for code generation #172

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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:

Expand Down
15 changes: 5 additions & 10 deletions code-gen-projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -101,12 +98,13 @@ 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` 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`
Expand Down Expand Up @@ -177,9 +175,6 @@ 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`._

### Tests

The tests for the generated code are defined in `tests` module in `lib.rs`. It has the following tests:
Expand All @@ -194,12 +189,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:

Expand Down
2 changes: 1 addition & 1 deletion code-gen-projects/java/code-gen-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tasks {
"-X", "generate",
"-l", "java",
"-n", "org.example",
"-d", ionSchemaSourceCodeDir,
"-A", ionSchemaSourceCodeDir,
"-o", generatedIonSchemaModelDir,
)
.workingDir(rootProject.projectDir)
Expand Down
2 changes: 1 addition & 1 deletion code-gen-projects/rust/code-gen-demo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 18 additions & 16 deletions src/bin/ion/commands/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,15 +62,18 @@ 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
.action(ArgAction::Append)
.value_name("DIRECTORY")
Arg::new("authority")
.long("authority")
.short('A')
.required(true)
.help("One or more directories that will be searched for the requested schema"),
.action(ArgAction::Append)
.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.",
),
)
}

Expand All @@ -91,16 +94,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<Box<dyn DocumentAuthority>> = vec![];

for authority in &authorities {
document_authorities.push(Box::new(FileSystemDocumentAuthority::new(Path::new(
authority,
))))
}
args.get_many::<String>("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);
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading