question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A `boolean` flag followed by a positional argument leads the the error `Flags cannot be assigned a value.`

See original GitHub issue

Information

  • OS: macOS
  • Version: 0.43.0
  • Terminal: macOS Term

Describe the bug A combination of a boolean flag and a positional argument leads the the error Flags cannot be assigned a value., which is wrong in my opinion.

To Reproduce Use the following settings:

// ...
    [Description("Input files or folders")]
    [CommandArgument(0, "[input]")]
    public string[] Input { get; set; } = Array.Empty<string>();

    [CommandOption("--dry-run")] public bool DryRun { get; init; } = false;
// ...

And call the app like this:

myapp --dry-run "my-input-folder/"

Expected behavior As --dry-run is a flag, I would expect spectre.console to handle the fact, taht there is a positional argument in the settings and parse this correctly. In my opinion this should work without error messages.

Workaround Putting the flag at the end works like expected:

myapp "my-input-folder/" --dry-run

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
patriksvenssoncommented, Oct 19, 2022

@sandreas -df is already supported.

1reaction
FrankRay78commented, Oct 19, 2022

Excellent write up and example @sandreas. I plan to fix the other issue, which is one step forward and will let me learn the parser and improve code coverage. Then come back to this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declaring Arguments, Options, and Flags | Documentation
Arguments are values given by a user and are read in order from first to ... Option and flag names are derived from...
Read more >
How to pass boolean arguments to go flags
As @fabrizioM said, boolean flags are a particular case because the presence of such a flag without an argument implies that the flag...
Read more >
Arg in clap - Rust
Pro tip: Flags (i.e. not positional, or arguments that take values) shouldn't be required by default. This is because if a flag were...
Read more >
ArgumentParser — Chapel Documentation 1.31
defaultValue – a value to assign the argument when a flag is not required, and a is not entered on the command line....
Read more >
Using Python Optional Arguments When Defining Functions
In this tutorial, you'll learn about Python optional arguments and how to define functions with default values. You'll also learn how to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found