Use Option for proper argument merging#402
Merged
gustavo-shigueo merged 1 commit intoAleph-Alpha:feat/clifrom May 29, 2025
gustavo-shigueo:feat/cli
Merged
Use Option for proper argument merging#402gustavo-shigueo merged 1 commit intoAleph-Alpha:feat/clifrom gustavo-shigueo:feat/cli
gustavo-shigueo merged 1 commit intoAleph-Alpha:feat/clifrom
gustavo-shigueo:feat/cli
Conversation
gustavo-shigueo
commented
May 9, 2025
Comment on lines
+56
to
+57
| #[arg(long, default_missing_value = "true", num_args = 0..=1)] | ||
| pub no_warnings: Option<bool>, |
Collaborator
Author
There was a problem hiding this comment.
This will parse CLI args as follows:
| CLI argument | Value |
|---|---|
| - | None |
--no-warnings |
Some(true) |
--no-warnings true |
Some(true) |
--no-warnings=true |
Some(true) |
--no-warnings false |
Some(false) |
--no-warnings=false |
Some(false) |
gustavo-shigueo
commented
May 9, 2025
| 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.
This will take whatever value is in the CLI args except None, in which case the config file is used instead, so now, if the config file has no-warnings = true and the CLI has --no-warnings=false, no_warnings will be Some(false), where as it would be true in the previous implementation
gustavo-shigueo
commented
May 9, 2025
| 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.
I don't know what's the "best" way to check for Some(true), a few options came to mind:
== Some(true).is_some_and(|x| x).is_some_and(std::convert::identity)
Let me know if you have any particular preference @NyxCode
This was referenced May 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Implement proper argument merging as described in this comment
Changes
Change boolean flags to be
Option<bool>and change themergemethod to prefer ´the CLI argument value over the configuration file