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.

Support options before arguments

See original GitHub issue

Especially for Unix/Linux platforms, the convention is usually to provide options before arguments:

Usage: grep [OPTION]... PATTERN [FILE]...
Usage: tar [OPTION...] [FILE]...
systemctl [OPTIONS...] {COMMAND} ...

Using boolean options before arguments currently gets incorrectly interpreted as assigning a value to the option flag. Would be good to support this ordering (preferably alongside existing behaviour).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
FrankRay78commented, Oct 18, 2022

This issue is occuring due to the way that CommandTreeParser is handling Options, namely peeking ahead to the next argument to determine what to do.

The following image is when I’ve specified the following on the command line --version --somethingelse and it’s currently parsing the --version Option. you can see that it’s peeked ahead and discovered another Option:

image

It knows to correctly ignore the following somethingelse Option and just proceed with the ‘No value?’ code further on.

When I specify the following on the command line --version somethingelse, then when it is parsing the --version Option, it peeks ahead and discovers something following it of TokenKind String:

image

CommandTreeParser.ParseOptionValue proceeds to attempt to set the --version Option to this value, unsuccessfully:

image


For @woutervanranst 's example above to work correctly,

restore --keep-pointers c:\Users\Wouter\Documents\Test

I guess the CommandTreeParser needs to

  1. check if --keep-pointers is a flag (ie. boolean value specified on the command settings class)
  2. if yes, then ignore the peek, proceed with the ‘No value?’ code further on, and parse c:\Users\Wouter\Documents\Test on the next pass (which should be handled here I suspect:) image
  3. if no, then attempt to set the --keep-pointers option value to c:\Users\Wouter\Documents\Test
0reactions
FrankRay78commented, Dec 11, 2022

This issue can be closed/marked as complete @patriksvensson, now that PR https://github.com/spectreconsole/spectre.console/pull/1048 has been successfully merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling command line options before and after an ...
So far I've been using getopt_long to parse options for a command line C program. Is there a way to stop getopt_long parsing...
Read more >
Support options before arguments · Issue #193
This issue is occuring due to the way that CommandTreeParser is handling Options, namely peeking ahead to the next argument to determine what...
Read more >
How to introduce support for command line options in a ...
Implement ordinary command line parsing using getopts . If that parsing is triggered at all, set a flag to keep track of this...
Read more >
Conventions for Command Line Options
The next simplest case are short options that take arguments. The argument follows the option. program -i input.txt -o output.txt. The space is ......
Read more >
Adding arguments and options to your Bash scripts
Try putting the parameters in a different order to see how that works. These parameters are positional, and that is a key consideration....
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