Skip to content

Commit

Permalink
Merge pull request #276 from stepchowfun/generate-flags
Browse files Browse the repository at this point in the history
Rename some flags
  • Loading branch information
stepchowfun authored Nov 8, 2021
2 parents df1fc4a + ad999f9 commit 7620ebc
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2021-11-08

### Changed
- Renamed `--rust-out` to `--rust` and `--typescript-out` to `--typescript`.

## [0.0.7] - 2021-10-25

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typical"
version = "0.0.7"
version = "0.1.0"
authors = ["Stephan Boyer <[email protected]>"]
edition = "2021"
description = "Algebraic data types for data interchange."
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Each field also has a type. If the type is missing, as it is for the `success` f
Now that we've defined some types, we can use Typical to generate the code for serialization and deserialization. For example, you can generate Rust code with the following:

```sh
typical generate email_api.t --rust-out email_api.rs
typical generate email_api.t --rust email_api.rs
```

Refer to the [example Rust project](https://github.com/stepchowfun/typical/tree/main/examples/rust) for how to automate this with a [Cargo build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html).
Expand Down Expand Up @@ -525,7 +525,7 @@ Notice that several types can take advantage of a more compact representation wh
Once Typical is [installed](#installation-instructions), you can use it to generate code for a schema called `main.t` with the following:

```sh
typical generate main.t --rust-out types.rs --typescript-out types.ts
typical generate main.t --rust types.rs --typescript types.ts
```

Here are the supported command-line options:
Expand Down Expand Up @@ -560,8 +560,8 @@ FLAGS:
-h, --help Prints help information
OPTIONS:
--rust-out <PATH> Sets the path of the Rust file to emit
--typescript-out <PATH> Sets the path of the TypeScript file to emit
--rust <PATH> Sets the path of the Rust file to emit
--typescript <PATH> Sets the path of the TypeScript file to emit
ARGS:
<SCHEMA_PATH> Sets the path of the schema
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
let output = Command::new("typical")
.arg("generate")
.arg(SCHEMA_PATH)
.arg("--rust-out")
.arg("--rust")
.arg(Path::new(&out_dir).join("types.rs"))
.output()
.expect("Failed to run Typical. Is it installed?");
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
let output = Command::new("typical")
.arg("generate")
.arg(SCHEMA_PATH)
.arg("--rust-out")
.arg("--rust")
.arg(Path::new(&out_dir).join("types.rs"))
.output()
.expect("Failed to run Typical. Is it installed?");
Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const BIN_NAME: &str = "typical";
// Command-line option and subcommand names
const GENERATE_SUBCOMMAND: &str = "generate";
const GENERATE_SUBCOMMAND_PATH_OPTION: &str = "generate-path";
const GENERATE_SUBCOMMAND_RUST_OUT_FILE_OPTION: &str = "rust-out";
const GENERATE_SUBCOMMAND_TYPESCRIPT_OUT_FILE_OPTION: &str = "typescript-out";
const GENERATE_SUBCOMMAND_RUST_OPTION: &str = "rust";
const GENERATE_SUBCOMMAND_TYPESCRIPT_OPTION: &str = "typescript";
const SHELL_COMPLETION_SUBCOMMAND: &str = "shell-completion";
const SHELL_COMPLETION_SUBCOMMAND_SHELL_OPTION: &str = "shell-completion-shell";

Expand All @@ -69,15 +69,15 @@ fn cli<'a, 'b>() -> App<'a, 'b> {
.required(true), // [tag:generate_subcommand_path_required]
)
.arg(
Arg::with_name(GENERATE_SUBCOMMAND_RUST_OUT_FILE_OPTION)
Arg::with_name(GENERATE_SUBCOMMAND_RUST_OPTION)
.value_name("PATH")
.long(GENERATE_SUBCOMMAND_RUST_OUT_FILE_OPTION)
.long(GENERATE_SUBCOMMAND_RUST_OPTION)
.help("Sets the path of the Rust file to emit"),
)
.arg(
Arg::with_name(GENERATE_SUBCOMMAND_TYPESCRIPT_OUT_FILE_OPTION)
Arg::with_name(GENERATE_SUBCOMMAND_TYPESCRIPT_OPTION)
.value_name("PATH")
.long(GENERATE_SUBCOMMAND_TYPESCRIPT_OUT_FILE_OPTION)
.long(GENERATE_SUBCOMMAND_TYPESCRIPT_OPTION)
.help("Sets the path of the TypeScript file to emit"),
),
)
Expand Down Expand Up @@ -234,14 +234,14 @@ fn entry() -> Result<(), Error> {
let rust_out = matches
.subcommand_matches(GENERATE_SUBCOMMAND)
.unwrap() // [ref:generate_subcommand]
.value_of(GENERATE_SUBCOMMAND_RUST_OUT_FILE_OPTION)
.value_of(GENERATE_SUBCOMMAND_RUST_OPTION)
.map(Path::new);

// Determine the path to the TypeScript output file, if provided.
let typescript_out = matches
.subcommand_matches(GENERATE_SUBCOMMAND)
.unwrap() // [ref:generate_subcommand]
.value_of(GENERATE_SUBCOMMAND_TYPESCRIPT_OUT_FILE_OPTION)
.value_of(GENERATE_SUBCOMMAND_TYPESCRIPT_OPTION)
.map(Path::new);

// Generate code for the schema.
Expand Down
2 changes: 1 addition & 1 deletion toast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ tasks:
command: |
# Run Typical on the integration test scenario.
cargo-offline run generate integration_tests/types/main.t \
--typescript-out integration_tests/typescript/src/types.ts
--typescript integration_tests/typescript/src/types.ts
# Validate the resulting TypeScript code.
(cd integration_tests/typescript && npm run check)
Expand Down

0 comments on commit 7620ebc

Please sign in to comment.