How to include a boolean option in front of an argument
SamEdwardes opened this issue · comments
Sam Edwardes commented
Hi Cliffy team, great work! I have really enjoyed using cliffy so far. I have a question about boolean options.
In my experience, it is a common CLI pattern to be able to have a boolean option flag that:
- takes no values
- can go before or after the commands argument(s)
For example:
apt-get install -y tree
apt-get install tree -y
The command works either way. I am having trouble doing the same with cliffy. Here is a reprex:
// reprex.ts
import { Command } from "https://deno.land/x/cliffy@v0.25.7/command/mod.ts";
await new Command()
.name("hello")
.version("0.1.0")
.description("hello world")
.option("-y, --yes [yes:boolean]", "Would you like to?",)
.arguments("<name:string>")
.action(({ yes }, name) => {
console.log("--yes:", yes)
console.log("argument:", name)
})
.parse(Deno.args);
❯ deno run reprex.ts "sam"
--yes: undefined
argument: sam
❯ deno run reprex.ts "sam" -y
--yes: true
argument: sam
❯ deno run reprex.ts -y "sam"
Usage: hello <name>
Version: 0.1.0
Description:
hello world
Options:
-h, --help - Show this help.
-V, --version - Show the version number for this program.
-y, --yes [yes] - Would you like to?
error: Option "--yes" must be of type "boolean", but got "sam". Expected values: "true", "false", "1", "0"
It is possible in cliffy to achieve the same behaviour is you get with apt-get install
?