Skip to content

Conversation

@gustavo-shigueo
Copy link
Collaborator

Goal

Implement proper argument merging as described in this comment

Changes

Change boolean flags to be Option<bool> and change the merge method to prefer ´the CLI argument value over the configuration file

Comment on lines +56 to +57
#[arg(long, default_missing_value = "true", num_args = 0..=1)]
pub no_warnings: Option<bool>,
Copy link
Collaborator Author

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:

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)

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),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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() {
Copy link
Collaborator Author

@gustavo-shigueo gustavo-shigueo May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@gustavo-shigueo gustavo-shigueo merged commit 39d4873 into Aleph-Alpha:feat/cli May 29, 2025
10 checks passed
@gustavo-shigueo gustavo-shigueo deleted the feat/cli branch May 29, 2025 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant