-
Notifications
You must be signed in to change notification settings - Fork 147
Use Option for proper argument merging #402
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,27 +53,27 @@ pub struct ExportConfig { | |
| pub output_directory: Option<PathBuf>, | ||
|
|
||
| /// Disables warnings caused by using serde attributes that ts-rs cannot process | ||
| #[arg(long)] | ||
| pub no_warnings: bool, | ||
| #[arg(long, default_missing_value = "true", num_args = 0..=1)] | ||
| pub no_warnings: Option<bool>, | ||
|
|
||
| /// Adds the ".js" extension to import paths | ||
| #[arg(long)] | ||
| pub esm_imports: bool, | ||
| #[arg(long, default_missing_value = "true", num_args = 0..=1)] | ||
| pub esm_imports: Option<bool>, | ||
|
|
||
| /// Formats the generated TypeScript files | ||
| #[arg(long)] | ||
| pub format: bool, | ||
| #[arg(long, default_missing_value = "true", num_args = 0..=1)] | ||
| pub format: Option<bool>, | ||
|
|
||
| /// Generates an index.ts file in your --output-directory that re-exports all | ||
| /// types generated by ts-rs | ||
| #[arg(long = "index")] | ||
| #[arg(long = "index", default_missing_value = "true", num_args = 0..=1)] | ||
| #[serde(rename = "index")] | ||
| pub generate_index_ts: bool, | ||
| pub generate_index_ts: Option<bool>, | ||
|
|
||
| /// Do not capture `cargo test`'s output, and pass --nocapture to the test binary | ||
| #[arg(long = "nocapture")] | ||
| #[arg(long = "nocapture", default_missing_value = "true", num_args = 0..=1)] | ||
| #[serde(rename = "nocapture")] | ||
| pub no_capture: bool, | ||
| pub no_capture: Option<bool>, | ||
| } | ||
|
|
||
| impl Default for ExportConfig { | ||
|
|
@@ -82,11 +82,11 @@ impl Default for ExportConfig { | |
| overrides: HashMap::default(), | ||
| config_file_path: None, | ||
| output_directory: Some(PathBuf::from("./bindings")), | ||
| no_warnings: false, | ||
| esm_imports: false, | ||
| format: false, | ||
| generate_index_ts: false, | ||
| no_capture: false, | ||
| no_warnings: None, | ||
| esm_imports: None, | ||
| format: None, | ||
| generate_index_ts: None, | ||
| no_capture: None, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -121,11 +121,11 @@ impl ExportConfig { | |
| Self { | ||
| output_directory: self.output_directory.or(other.output_directory), | ||
| overrides: other.overrides, | ||
| no_warnings: self.no_warnings || other.no_warnings, | ||
| esm_imports: self.esm_imports || other.esm_imports, | ||
| format: self.format || other.format, | ||
| generate_index_ts: self.generate_index_ts || other.generate_index_ts, | ||
| no_capture: self.no_capture || other.no_capture, | ||
| no_warnings: self.no_warnings.or(other.no_warnings), | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will take whatever value is in the CLI args except |
||
| esm_imports: self.esm_imports.or(other.esm_imports), | ||
| format: self.format.or(other.format), | ||
| generate_index_ts: self.generate_index_ts.or(other.generate_index_ts), | ||
| no_capture: self.no_capture.or(other.no_capture), | ||
| config_file_path: None, | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ fn main() -> Result<()> { | |
| let metadata_content = fs::read_to_string(&metadata_path)?; | ||
| let metadata = Metadata::try_from(&*metadata_content)?; | ||
|
|
||
| if !args.generate_index_ts || metadata.is_empty() { | ||
| if !args.generate_index_ts.unwrap_or(false) || metadata.is_empty() { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what's the "best" way to check for
Let me know if you have any particular preference @NyxCode |
||
| return Ok(()); | ||
| } | ||
|
|
||
|
|
@@ -88,7 +88,7 @@ fn main() -> Result<()> { | |
|
|
||
| index.write_all(NOTE)?; | ||
|
|
||
| if args.generate_index_ts { | ||
| if args.generate_index_ts.unwrap_or(false) { | ||
| for path in metadata.export_paths() { | ||
| index.write_fmt(format_args!("\nexport * from {path:?};"))?; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will parse CLI args as follows:
None--no-warningsSome(true)--no-warnings trueSome(true)--no-warnings=trueSome(true)--no-warnings falseSome(false)--no-warnings=falseSome(false)