Add support to print help/usage of util.parseArgs
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.3k
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 283
Description
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:
- Include help text for each ParseArgsOptionConfig to include help text for each option in particula:
foo: {
type: 'boolean',
short: 'f',
help: 'enable foo',
},
- 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: {
// ...
}
});
- Add the
--help/-hoption to print the generated usage information either:
- always add the
--help/-hoption, and automatically print the usage and exit the process when parsing the args (E.g. how python's builtinargparsedoes 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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le point d’entrée util.parseArgs et examinez le comportement existant de ParseArgsConfig et ParseArgsOptionConfig. Déterminez quelle API de génération de l’aide et quel comportement de --help/-h doivent être pris en charge ; le travail est terminé lorsque la conception choisie est implémentée pour les textes d’utilisation des commandes et des options.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, node.js
- Domaine
- cli
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Calme
- Clarté
- À clarifier
- Accessibilité débutants
- 35/100