meow
meow copied to clipboard
Idea: adopt docopt
It would be awesome if meow could adopt http://docopt.org/ to deduce additional behaviour from the help text. This could be
- disabled by default
- help with #69
- add more validation to user input
- ...
That was initially the long-term plan, but after having used Swift for a while, I've come to appreciate type safety, so now I'm leaning more towards going the other way, and generating the help text from APIs instead. No matter how well specified something is, parsing will have ambiguities.
Understood. Are you aiming for a declarative API or something like yargs
?
Something like yargs
, but less comprehensive and opinionated, and not a chainable API.
Pretty much just expanding on the existing options object:
{
flags: {
rainbow: {
type: 'boolean',
alias: 'r'
}
}
}
I imagine we could add more options there, and a way to define command and examples too.
hi,
just wanted to post here, maybe it's of use to anyone else.
just build my quick and rough self generating usage message from the flags array
would be lovely to have something like this already included
thank you for this package, it s lovely
const meow = require("meow")
// shorthand for default values
const defaultValue = s => flags[s].default
const options = f => {
let r = ""
let l = 10
let s = " "
console.log(...f)
let fullFlags = {
help: { description: "This message" },
...f,
version: { description: "Display app version and quit" },
}
for (let [name, flag] of Object.entries(fullFlags)) {
l = Math.max(l, name.length)
}
console.log("max", l)
for (let [name, flag] of Object.entries(fullFlags)) {
console.log(name, flag)
let i = ` --${name}`
i += flag.type ? ` ${flag.type}` : ``
r += i
r += s.repeat(l + 15 - i.length)
r += `${flag.description}`
r += flag.default ? ` (default ${flag.default})` : ``
r += `\n`
}
return r
}
const flags = {
"metrics-port": {
type: "int",
default: 8888,
description: "Prometheus metrics port",
},
"redis-server": {
type: "string",
default: "localhost:6379",
description: "Redis host:port",
},
"deepstream-prefix": {
type: "string",
default: "pending",
description: "Namespace for all deepstream data",
},
}
const usage = `
Usage
$ pending-transactions-deepstream [options]
Options
${options(flags)}
`
const cli = meow(usage, { flags })
We should still add a link to http://docopt.org/, to encourage better descriptions for new developers. Or if you have another standard that you like more, I would be interested to hear that.