Comments (4)
Yeah. I'll admit that your example is not something I've seen in a CLI before, and sywac is probably not a good choice for that use-case at the moment.
Thanks for reporting!
from sywac.
@elliot-nelson Hi - sorry I've been so AWOL on providing help with sywac!
My immediate thought would be to interpret -l
as an array type (so it can hold multiple values) and then use the 1st element as the "look for" value and the 2nd element as the "update" value.
Otherwise, we might need to plug in a custom type for either the -l
flag (to hold multiple values in a more suitable way) or for the command type (to override how "local" flags do or do not override "global" flags - which I'm not entirely sure is possible at the moment, but we could probably figure out something).
To plug in your own type, you can either use sywac.registerFactory(nameString, factoryFunction)
or sywac.custom(typeInstance)
.
from sywac.
@elliot-nelson Here's a super naive/minimalistic example of what I was describing:
require('../sywac')
.configure({ name: 'slalom' })
.command('query', {
setup: sywac => {
sywac
.array('-l')
.string('-i')
.command('update', {
run: argv => {
console.log(`look for ${argv.l[0]} in ${argv.i} and update to ${argv.l[1]}`)
}
})
}
})
.showHelpByDefault()
.parseAndExit()
$ node issue45.js query -l 'retired' -i '10.11.*' update -l 'Retired'
look for retired in 10.11.* and update to Retired
Does something like that make sense for your use-case?
from sywac.
Thanks for the example! That does make sense, but in reality I probably couldn't rely on it - because there are many fields that can be used as query, update, or both, the array would not always be 2 elements long.
For each field that is 1 element long, there's no way to tell whether the value is supposed to be a query or an update, because the params aren't actually attached to the command in any way.
(And maybe they shouldn't be - not every command line tool should be represented. Imagine trying to represent a CLI like ImageMagick for example - totally different paradigm.)
from sywac.
Related Issues (20)
- How to specify certain options are required? HOT 3
- cliMessage usage instructions for command print with wrong context? HOT 1
- How to prevent unknown options HOT 2
- Should certain stdout messages go to stderr? HOT 3
- Respect ANSI codes when applying maxWidth HOT 3
- How to provide commands with additional data? HOT 5
- Default commands with positional args behave unexpectedly HOT 6
- Control style with a flag HOT 3
- Best practice for error output? HOT 14
- Proposal for "run" handler at Api level HOT 8
- Customize "--" flag that delimits extra arguments HOT 2
- Convert kebab-case flags to camelCase HOT 2
- feature: document exit codes in help text
- Any typings / d.ts files for sywac? HOT 4
- Best way to add implicitcommands? HOT 3
- Prep for Hacktoberfest HOT 3
- Welcome, Hacktoberfest 2020!
- Add "--no-flag" support for Boolean types HOT 5
- Trying to get in touch regarding a security issue HOT 7
- Better error generation if file doesn't exist
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 sywac.