nodejs / nodejs/node

Add support to print help/usage of util.parseArgs

Aperta
#56,184 8 commenti 16 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature request
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

What is the problem this feature will solve?

An almost ubiquitous practice of writing a CLI is including a help command in the CLI itself. Currently anyone using util.parseArgs needs to write their own help command. This, in my opinion, makes parseArgs incomplete.

What is the feature you are proposing to solve the problem?

My suggestion is to include the ability to prin help/usage information generated directly from the config given to parseArgs. A minimum would be something along the lines of:

  1. Include help text for each ParseArgsOptionConfig to include help text for each option in particula:
foo: {    
 type: 'boolean',    
 short: 'f',   
 help: 'enable foo',
},
  1. Add a main help text to the ParseArgsConfig as well, to include details on what the CLI as a whole:
parseArgs({ 
  help: 'Use this command to achieve foo',
  options: {
    // ...
  }
});
  1. Add the --help/-h option to print the generated usage information either:
  • always add the --help/-h option, and automatically print the usage and exit the process when parsing the args (E.g. how python's builtin argparse does it); this would be a breaking change since it may conflict with other similar options implemented already.
  • add a new option to the ParseArgsConfig to enable autogenerated help option if desired
parseArgs({ 
  enableHelp: true,
  help: 'Use this command to achieve foo',
  options: {
    // ...
  }
});
  • simply provide a method to print the usage and let the user implement it themselves in userland
const { values, positionals, printUsage } = parseArgs({
  help: 'Use this command to achieve foo',
  options: {
    help: {
      type: "boolean",
      short: "h",
      help: "print command line options and exit"
    }
  }
});
if (values.help) {
  printUsage();
  process.exit(0);
}
What alternatives have you considered?

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso util.parseArgs e rivedi il comportamento esistente di ParseArgsConfig e ParseArgsOptionConfig. Determina quale API per la generazione dell’help e quale comportamento di --help/-h debbano essere supportati; il lavoro è completo quando il design scelto è implementato per i testi di utilizzo dei comandi e delle opzioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
cli
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.