Skip to content

Conversation

edolstra
Copy link
Member

Motivation

This allows specifying flags that are mandatory. The motivation was nix nario export (#13969), which has a required --format flag.

Note: The timesUsed counter could also be used to warn about flags being set multiple times (#13899).

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added the new-cli Relating to the "nix" command label Sep 26, 2025
Comment on lines +515 to +516
if (flag->required && flag->timesUsed == 0)
throw UsageError("required argument '--%s' is missing", name);
Copy link
Member

Choose a reason for hiding this comment

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

Can we list multiple such flags?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there can be multiple required flags.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I mean collect them all and throw error with all of them

@Ericson2314 Ericson2314 added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Sep 26, 2025
Comment on lines +208 to +210

// FIXME: this should be private, but that breaks designated initializers.
size_t timesUsed = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's really ugly that Flag becomes mutable. Can we avoid this by storing the use-count separately? I would hope that Flag stays an immutable description with a callback. Can't we instead track if the argument has been specified multiple times in the Handler?

Copy link
Member

Choose a reason for hiding this comment

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

Yes I would prefer that too, thanks for catching @xokdvium

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's a problem since Args owns the Flags anyway (i.e. it was already mutable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. new-cli Relating to the "nix" command
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants