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

Suggestion: optional summary parameter for command and subcommands #203

Open
thetos7 opened this issue Jul 27, 2023 · 0 comments
Open

Suggestion: optional summary parameter for command and subcommands #203

thetos7 opened this issue Jul 27, 2023 · 0 comments

Comments

@thetos7
Copy link

thetos7 commented Jul 27, 2023

This is a suggestion to add an optional summary configuration field in command and subcommands which would be referenced when a short description is needed/preferable, like when listings choices of subcommands.

This would allow having both a concise description when a command or subcommand appears in a list in another command's help, and a long-form description with all the necessary details to keep in mind when using the CLI when viewing the command's help.

Example

consider the following example:

#!/bin/env node
// machine.ts

import { command, subcommands, binary } from "cmd-ts";

const brewCoffeeCmd = command({
  name: "brew coffee",
  description: // long description, maybe featuring notes or example usage
`Brew a cup of coffee.

Lorem ipsum dolor sit amet...
`,
  summary: "Brew a cup of coffee",
  args: { /* args */ },
  handler: () => {
    console.log("Brewing coffee...");
  },
});

const brewCocoaCmd = command({
  name: "brew cocoa",
  description: // long description, maybe featuring notes or example usage
`Brew a cup of hot cocoa.

Lorem ipsum dolor sit amet...
`,
  summary: "Brew a cup of hot cocoa",
  args: { /* args */ },
  handler: () => {
    console.log("Brewing hot cocoa...");
  },
});

const brewCmd = subcommands({
  name: "brew",
  description: // long description, maybe featuring notes or example usage
`Brew a cup of a selection of hot drinks.

Lorem ipsum dolor sit amet...
`,
  summary: "Brew a hot drink",
  cmds: {
    coffee: brewCoffeeCmd,
    cocoa: brewCocoaCmd,
  },
});

const payCmd = command({
  name: "pay",
  description: // long description, maybe featuring notes or example usage
`Pay for a drink.

Lorem ipsum dolor sit amet...
`,
  summary: "Pay your drink",
  args: { /* args */ },
  handler: () => {
    console.log("Payment complete, enjoy your drink!");
  },
});

const machineCmd = subcommands({
  name: "machine",
  description: "coffee machine CLI utility",
  summary: "available but unused?",
  cmds: {
    brew: brewCmd,
    pay: payCmd,
  },
});

void run(binary(machineCmd), process.argv);

Which would generate the following help pages:

$> machine --help
machine <subcommand>
> coffee machine CLI utility

Where <subcommand> can be one of:

- brew - Brew a hot drink
- pay - Pay your drink

$> machine brew --help
brew <subcommand>
> Brew a cup of a selection of hot drinks.

Lorem ipsum dolor sit amet...

Where <subcommand> can be one of:

- coffee - Brew a cup of coffee
- cocoa - Brew a cup of hot cocoa

$> machine pay --help
pay
> Pay for a drink.

Lorem ipsum dolor sit amet...

and so on.

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

1 participant