nodejs / nodejs/node

Add support to print help/usage of util.parseArgs

オープン
#56,184 コメント 8 件 リアクション 16 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

エントリポイントの util.parseArgs から開始し、既存の ParseArgsConfig と ParseArgsOptionConfig の動作を確認します。どのヘルプ生成 API と --help/-h の動作をサポートすべきかを決定します。選択した設計がコマンドとオプションの使用方法テキストに実装されれば、作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
cli
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。