minimist vs caporal vs commander vs yargs
コマンドライン引数解析ライブラリ
minimistcaporalcommanderyargs類似パッケージ:

コマンドライン引数解析ライブラリ

コマンドライン引数解析ライブラリは、Node.jsアプリケーションでコマンドライン引数を簡単に処理するためのツールです。これらのライブラリは、ユーザーがコマンドラインから入力したオプションや引数を解析し、アプリケーションの動作を制御するための便利な機能を提供します。これにより、開発者は複雑な引数の処理を簡素化し、ユーザーに対して直感的なインターフェースを提供できます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
minimist69,538,96066354.5 kB143年前MIT
caporal22,0293,461-286年前MIT
commander028,020209 kB92ヶ月前MIT
yargs011,458231 kB31010ヶ月前MIT

機能比較: minimist vs caporal vs commander vs yargs

使いやすさ

  • minimist:

    Minimistは、非常にシンプルで軽量なライブラリで、基本的な引数解析に特化しています。使い方が簡単で、すぐに導入できますが、機能は限られています。

  • caporal:

    Caporalは、コマンドやオプションの定義が非常に直感的で、すぐに使い始めることができます。特に、デフォルトのヘルプメッセージが自動生成されるため、ユーザーにとっても使いやすいです。

  • commander:

    Commanderは、シンプルなAPIを提供し、コマンドやオプションの定義が容易です。特に、サブコマンドのサポートが強力で、複雑なCLIを構築するのに適しています。

  • yargs:

    Yargsは、豊富な機能を持ちつつも、使いやすさを重視しています。特に、コマンドやオプションの定義が簡単で、詳細なヘルプメッセージを自動生成できます。

機能の豊富さ

  • minimist:

    Minimistは、非常にシンプルな引数解析を提供しますが、機能は最小限で、複雑なオプションやバリデーションには向いていません。

  • caporal:

    Caporalは、コマンドのネストやオプションのバリデーションなど、基本的な機能を提供しますが、他のライブラリに比べると機能は限られています。

  • commander:

    Commanderは、サブコマンド、オプションのバリデーション、デフォルト値の設定など、豊富な機能を提供し、複雑なCLIを構築するのに適しています。

  • yargs:

    Yargsは、詳細なバリデーション、コマンドのネスト、動的なオプションの生成など、非常に豊富な機能を提供し、複雑なCLIアプリケーションに最適です。

パフォーマンス

  • minimist:

    Minimistは、非常に軽量で高速な引数解析を提供します。小規模なスクリプトやアプリケーションに最適です。

  • caporal:

    Caporalは、比較的軽量で、パフォーマンスも良好です。ただし、機能が増えるとパフォーマンスに影響が出る可能性があります。

  • commander:

    Commanderは、効率的に設計されており、パフォーマンスも良好です。特に、大規模なコマンドラインアプリケーションにおいてもスムーズに動作します。

  • yargs:

    Yargsは、機能が豊富ですが、パフォーマンスに影響を与えることがあります。特に、複雑なオプションを扱う場合は注意が必要です。

拡張性

  • minimist:

    Minimistは、シンプルさを重視しているため、拡張性はほとんどありません。

  • caporal:

    Caporalは、基本的な拡張機能を提供しますが、他のライブラリに比べると拡張性は限られています。

  • commander:

    Commanderは、プラグインのサポートがあり、拡張性が高いです。特に、サブコマンドやオプションを追加するのが容易です。

  • yargs:

    Yargsは、豊富な機能を持ち、拡張性も高いです。特に、カスタムコマンドやオプションを簡単に追加できます。

学習曲線

  • minimist:

    Minimistは、非常にシンプルであるため、学習曲線はほとんどありません。すぐに使い始めることができます。

  • caporal:

    Caporalは、直感的なAPIを持っているため、学習曲線は比較的緩やかです。特に、CLIアプリケーションを初めて作成する開発者にとって使いやすいです。

  • commander:

    Commanderは、シンプルな構文を持っており、学習曲線は緩やかです。特に、基本的なコマンドラインアプリケーションを作成するのに適しています。

  • yargs:

    Yargsは、豊富な機能を持つため、最初は少し学習曲線が急になるかもしれませんが、使いこなすと非常に強力です。

選び方: minimist vs caporal vs commander vs yargs

  • minimist:

    Minimistは、軽量でシンプルな引数解析を求める場合に適しています。特に、複雑な機能が不要な小規模なスクリプトやアプリケーションに最適です。

  • caporal:

    Caporalは、コマンドラインアプリケーションを迅速に構築したい場合に最適です。特に、複数のコマンドやオプションを持つアプリケーションにおいて、シンプルで直感的なAPIを提供します。

  • commander:

    Commanderは、シンプルで強力なコマンドラインインターフェースを必要とする場合に選択すべきです。特に、複雑なコマンドやサブコマンドを持つアプリケーションに適しています。

  • yargs:

    Yargsは、豊富な機能を持ち、複雑なコマンドラインオプションを扱う必要がある場合に選択すべきです。特に、詳細なバリデーションやヘルプメッセージの生成が必要な場合に便利です。

minimist のREADME

minimist Version Badge

github actions coverage License Downloads

npm badge

parse argument options

This module is the guts of optimist's argument parser without all the fanciful decoration.

example

var argv = require('minimist')(process.argv.slice(2));
console.log(argv);
$ node example/parse.js -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
$ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
{
	_: ['foo', 'bar', 'baz'],
	x: 3,
	y: 4,
	n: 5,
	a: true,
	b: true,
	c: true,
	beep: 'boop'
}

security

Previous versions had a prototype pollution bug that could cause privilege escalation in some circumstances when handling untrusted user input.

Please use version 1.2.6 or later:

methods

var parseArgs = require('minimist')

var argv = parseArgs(args, opts={})

Return an argument object argv populated with the array arguments from args.

argv._ contains all the arguments that didn't have an option associated with them.

Numeric-looking arguments will be returned as numbers unless opts.string or opts.boolean is set for that argument name.

Any arguments after '--' will not be parsed and will end up in argv._.

options can be:

  • opts.string - a string or array of strings argument names to always treat as strings

  • opts.boolean - a boolean, string or array of strings to always treat as booleans. if true will treat all double hyphenated arguments without equal signs as boolean (e.g. affects --foo, not -f or --foo=bar)

  • opts.alias - an object mapping string names to strings or arrays of string argument names to use as aliases

  • opts.default - an object mapping string argument names to default values

  • opts.stopEarly - when true, populate argv._ with everything after the first non-option

  • opts['--'] - when true, populate argv._ with everything before the -- and argv['--'] with everything after the --. Here's an example:

    > require('./')('one two three -- four five --six'.split(' '), { '--': true })
    {
      _: ['one', 'two', 'three'],
      '--': ['four', 'five', '--six']
    }
    

    Note that with opts['--'] set, parsing for arguments still stops after the --.

  • opts.unknown - a function which is invoked with a command line parameter not defined in the opts configuration object. If the function returns false, the unknown option is not added to argv.

install

With npm do:

npm install minimist

license

MIT