Comments (13)
Yeah I'm trying to think of how this could be added in a generally GNU-ish way but I can't think of anything that doesn't introduce yet another option. :/ It's a real edge case IMO, I don't see many programs use --
as a major delimiter.
Also, for the
find
style behaviour, there's no way to do this in arg today. Do you want to try and support this somehow?
Not really, no - their flags are positional as well (as in, order of flags matters), and they use single hyphens for long flags. It's an entirely different parsing scheme that would more than likely be easier to implement in a custom manner - definitely out of scope for arg
.
from arg.
I'm ๐ on this, this isn't how --
is supposed to work. Seems like you're trying to fix an XY problem - can you expand a bit on what you're trying to do by splitting the parsed arguments?
from arg.
@Qix- It's how the library works: https://github.com/Qard/onchange.
from arg.
I would, of course, be open to hear how this should work instead of how it does work. Using --
seems like a reasonable use-case here to me. But since this is an existing library and existing feature in other libraries like minimist
it would be nice to have - even if you say it shouldn't be done.
from arg.
I don't like the argument of "other libraries do it, therefore..." because a lot of other libraries have large scopes in order to make everyone that has a niche use case happy ๐
Which is a large reason why arg
was written.
For what it's worth, this pattern of option parsing isn't common in the UNIX world.
Some examples of programs that tackle this in different ways are:
xargs
, which treats the first positional as the beginning of the commandfind
, which uses-exec
and a subsequent\;
to denote the beginning and end of a command to run against each found entryentr
, which reads a file listing from standard input
--
is the canonical way to say "stop reading the rest of the CLI as options/flags and treat them as positionals". That is the mental contract users have when using CLI's.
The only way I'd be comfortable handling this is to have an option stopAtDashes: true
or something like that, akin to stopAtPositional
. But I feel strongly against having a separate array for arguments.
P.S. excuse any double dots, I know they look really snarky but Apple makes dodgy keyboards lately and some keys tend to hit twice. Currently, my period key is affected. I think I edited all of them out ๐
from arg.
@Qix- To be honest, I agree and it's not really an argument at all for supporting this (that would be a bad argument). The argument is that this is an existing use-case and the change does not significantly increased complexity or types (it adds around 5 lines to handle --
separately inside an if handler['--']
). I do understand if you don't want to support this in any case because it's "non-unix-like", in which case we can update the README.md
or CONTRIBUTING.md
and indicate non-unix-like behaviour is discouraged.
It does seem like I could refactor onchange
to use stopAtPositional
going forward, move current pattern usage behind -p
or something and release a new major version to use arg
. This just seemed like a nice compromise for today's library as many people understand how it works already.
FWIW, I avoided making it a config option because it makes the type system weird - just using opts['--']
was super nice because it required zero type system changes, things "just work".
from arg.
@Qix- Also, for the find
style behaviour, there's no way to do this in arg
today. Do you want to try and support this somehow? Maybe a separate symbol for "sub-command" parsing?
from arg.
Actually, a new option might be okay in this case:
{
literalDashes: true
}
That would cause --
to be treated as a positional, allowing you to split ._
how you'd like. It would also solve a few other use-cases as well.
Further, it plays nicely with stopAtPositional
, which is what I was worried about.
from arg.
This might work but itโs still an incompatible change for onchange
since thereโs no specific order required today for the patterns and CLI args. I donโt think itโs incompable with this suggestion either so I donโt think I should block you if it helps other cases!
from arg.
Could you explain your use case then? With the change in #35, you can achieve what you want here in this ticket.
from arg.
@Qix- It's not compatible because onchange "**/*.ts" -k -- npm start
would mean something else in #35 compared to #33 (#35 would stop parsing when you hit "**/*.ts"
instead of --
).
from arg.
No, #35 doesn't stop parsing. It just includes --
in the ._
array instead of treating it specially. However, you're right - it would then try to parse any arguments after the --
as flags as per the spec object passed to arg
, which presents a new problem for you.
In onchange
, what I would personally do is just to .slice()
based on process.argv
since it's a really niche use-case, and then just run the first of the two arrays through arg
. Plus, that will make more sense looking at the code.
const dashIdx = process.argv.indexOf('--');
if (dashIdx === -1) {
throw new Error('no program arguments given');
}
const programArgs = process.argv.slice(dashIdx);
const args = arg(
{
/* ... */
}, {
argv: argv.slice(2, dashIdx)
}
);
It's untested, but that should do it, and IMO it makes it very clear to me (the reader) what's happening.
from arg.
@Qix- Sure, that makes sense ๐
from arg.
Related Issues (20)
- Ability to "stop early" HOT 9
- Add code coverage analysis + badge
- Print help? HOT 2
- Support defaults HOT 8
- `arg` parses quoted argument values HOT 2
- Support for required arguments? HOT 2
- Everything after "=" gets stripped off in long args with "=" in value HOT 1
- Short args can't be used with = HOT 7
- Issues parsing negative numbers when passed without `=` HOT 13
- What's the default value for Boolean type? HOT 3
- Is there other way to input array of strings? HOT 3
- Add support for running in the browser HOT 2
- Typescript build error HOT 1
- Flags with optional values HOT 2
- TypeScript typings error for handlers
- Add support for Deno HOT 4
- Convert to ES Modules
- Short options get splited in permissive being true
- ReDoS vulnerability in index.js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arg.