Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: adopt docopt #71

Open
marionebl opened this issue Oct 18, 2017 · 6 comments
Open

Idea: adopt docopt #71

marionebl opened this issue Oct 18, 2017 · 6 comments

Comments

@marionebl
Copy link

It would be awesome if meow could adopt http://docopt.org/ to deduce additional behaviour from the help text. This could be

@sindresorhus
Copy link
Owner

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.

@marionebl
Copy link
Author

Understood. Are you aiming for a declarative API or something like yargs?

@sindresorhus
Copy link
Owner

Something like yargs, but less comprehensive and opinionated, and not a chainable API.

@sindresorhus
Copy link
Owner

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.

@tzapu
Copy link

tzapu commented Jan 23, 2018

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 })

@synox
Copy link

synox commented Oct 13, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants