Comments (4)
Hi @oganexon,
You can use the .stopEarly() method as descriped in the readme to pass unkown options to your command. If enabled, all options, starting from the first none option argument, will be passed as arguments to the action handler.
Literal arguments won't be passed to the action handler atm, but this feature is in progress.
from deno-cliffy.
Great, almost there
If i follow the example I can do:
$ deno run https://deno.land/x/cliffy/examples/command/stop-early.ts -d warning server -p 80
options: { debugLevel: "warning" }
script: server
args: [ "-p", "80" ]
But how can I do:
$ deno run https://deno.land/x/cliffy/examples/command/stop-early.ts --foo warning server -p 80
from deno-cliffy.
This is not possible with .stopEarly()
, because .stopEarly()
needs to know which options belongs to the command and which to the arguments. You need an argument to separate these options.
In your example, --foo
will be interpreted as option from the stop-early.ts
command and warning server -p 80
will be passed as arguments because warning
is the first none option argument.
There is also another method called .useRawArgs()
. If you call this method, all options are interpreted as arguments. But this will also disable the handling of all build in options like --help
and --version
.
from deno-cliffy.
Perfect, I managed to have help and get the args
export class RunCommand extends DefaultCommand {
public constructor() {
super();
this.description(desc)
.useRawArgs()
.action((_, ...args) => {
if (["-h", "--help", "help"].includes(args[0])) {
Deno.stdout.writeSync(new TextEncoder().encode( this.getHelpCommand().getHelp() ) );
Deno.exit()
}
console.log(args)
});
}
}
from deno-cliffy.
Related Issues (20)
- Add env option to option method HOT 3
- Feedback wanted: Default prompt output to stderr HOT 4
- Make input/output stream configurable for all prompts
- Default validator/transform fail on Checkbox prompt with numeric or non-string values HOT 1
- How to include a boolean option in front of an argument
- Add hierarchical prompt select HOT 1
- completions command: "complete method" / "custom type" not working HOT 1
- disallow generating completions if name is not set HOT 2
- Feature: Support extracting options/args types from Command. HOT 4
- Enable customization of exit code for `required` env var HOT 2
- Site is down HOT 2
- show required options on usage
- flags without argument ('empty flags') are hard to use as boolean flag HOT 3
- Release cadence HOT 2
- Ordered/Ranked list prompt
- Table layout broken for various types of Unicode characters
- node support via dnt
- Checkbox prompt thinks there's a group when there isn't HOT 1
- Navigating back on the outer most prompt level can select a disabled item HOT 1
- Feature: Ability to parse arguments without execution HOT 3
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 deno-cliffy.