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.

Unclear behavior with defaultOption and more-than-one multiple args

See original GitHub issue

Given this config:

const optionDefinitions = [
  { name: 'verbose', alias: 'v', type: Boolean },
  { name: 'src', type: String, multiple: true },
  { name: 'foo', type: String, multiple: true, defaultOption: true },
  { name: 'timeout', alias: 't', type: Number }
]

It is not clear what would be the behavior for:

$ example --verbose --timeout=1000 --src one.js two.js three.js

What’s clear here:

  • one.js is one of the src values.

What’s not clear here:

  • Are two.js and three.js values for src, or foo?

The common-best-practice (specifically in unix-like systems) is to have two.js and three.js as foo values. However, the examples in README.md have a light indication that these values would be considered as src’s. (At least some people that I have talked to have had this understanding from the doc.)

Would be great if we could make this more clear in the docs.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
75lbcommented, Apr 22, 2022

enabling multiple plugins would be like -p first.js -p second.js -p "more-plugins/*.js" (the command would be responsible for glob expansion).

the majority of users don’t quote glob expressions, meaning the shell expands the glob expression before passing the result into node… this results in command-line-args parsing a process.argv looking something like ['-p', 'more-plugins/one.js', 'more-plugins/two.js', 'more-plugins/three.js'] (i.e. an option followed by one or more values)… We need to support this form…

And GNU adds the long options (doube-hyphen), allowing --plugin first.js --plugin second.js ....

Use lazyMultiple to get this syntax form in command-line-args…

Thanks for the feedback - if you have ideas to improve the documentation, feel free to edit the wiki or submit a PR… i too will review the docs when I get round to working on the next version…

0reactions
besfahbodcommented, Apr 21, 2022

So, in POSIX proper, enabling multiple plugins would be like -p first.js -p second.js -p "more-plugins/*.js" (the command would be responsible for glob expansion).

And GNU adds the long options (doube-hyphen), allowing --plugin first.js --plugin second.js ....

https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

I think the idea is that if you expect many arguments of some kind, you would make sure there’s a short form for it, keeping the overhead low.

That said, the POSIX and GNU behaviors are kind of ancient now, and some newer major products actually use something a bit more flexible than that. However, I’m not familiar with any major system behavior the way this project does.

I wanted to refer to the docs for Rust’s clap library on how they handle multiple occurrences (which I believe should be GNU-friendly), however I couldn’t find it in the docs, and I think we need to write a demo for it to show how it behaves… (https://docs.rs/clap/latest/clap/)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid syntax. Default option is not allowed more than '2' time(s)
It is quite simple but hidden. run setx /? and I suppose the answer is there. The PATH you give as a parameter...
Read more >
List of cognitive biases - Wikipedia
Cognitive biases are systematic patterns of deviation from norm and/or rationality in judgment. They are often studied in psychology, sociology and ...
Read more >
Bash Reference Manual - GNU.org
This includes arguments to builtin commands such as declare that accept assignment statements (declaration commands). When ' += ' is applied to ...
Read more >
CommandLine 2.0 Library Manual - Documentation - LLVM
Introduction¶. This document describes the CommandLine argument processing library. It will show you how to use it, and what it can do.
Read more >
survival.pdf
Arguments formula a formula object, with the response on the left of a '~' operator and the terms, separated by + operators, on...
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