MassifApp.CommandLine 1.0.6

dotnet add package MassifApp.CommandLine --version 1.0.6
NuGet\Install-Package MassifApp.CommandLine -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MassifApp.CommandLine" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MassifApp.CommandLine --version 1.0.6
#r "nuget: MassifApp.CommandLine, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MassifApp.CommandLine as a Cake Addin
#addin nuget:?package=MassifApp.CommandLine&version=1.0.6

// Install MassifApp.CommandLine as a Cake Tool
#tool nuget:?package=MassifApp.CommandLine&version=1.0.6

MassifApp.CommandLine

概要

シンプルなコマンドラインパーサです。
dockerコマンドのような複雑な設定はできません。
マイクロソフト社のMicrosoft.Extensions.CommandlineUtilsに近いです(むしろ参考にしています)。
LINQやラムダ式を駆使してワンライナーでも実現できるけど、もう少し複雑なパラメータにしたい、といった場合の用途に適しています。

コマンドライン引数の種類

以下の種類を扱うことができます。

Argument

入出力ファイル名など、アプリケーションに必須なコマンドライン引数に適しています。

Option

機能のオン/オフやヘルプ表示など、アプリケーションの機能やふるまいに関するコマンドライン引数に適しています。

Command

閾値や追加情報など、アプリケーションに対する設定値に関するコマンドライン引数に適しています。

詳細

  • ヘルプ表示オプション -? | -h | --help は標準で実装されています。
  • コマンドライン引数が少なく単純であれば個別の変数で扱うこともできますが、そうでなければCommandLineParserクラスを継承して利用することを検討してください。
  • コマンドライン引数をパースした結果、間違った引数だった場合は例外をスローします。このときの例外処理はOnErrorメソッドでデリゲートを渡すことでカスタマイズ可能です。

二つの必須なコマンドライン引数:
CommandLineParser parser = new();
var argument1 = parser.RegistArgeument("argument1", "mandate param 1st", true);
var argument2 = parser.RegistArgeument("argument2", "mandate param 2nd", true);
parser.Parse(args);
Console.WriteLine("1st:{0}", argument1.Value);
Console.WriteLine("2nd:{0}", argument2.Value);
CommandとOptionそれぞれ一つ:
CommandLineParser parser = new();
var command1 = parser.RegistCommand("-c|--command", "command is number", 50, new ValueParserInteger(0, 100));
var option1 = parser.RegistOption("-o|--option", "option is optional");
parser.Parse(args);
Console.WriteLine("Command is {0}", command1.Value);
Console.WriteLine("Option Enabled = {0}", option1.Value);
ヘルプ表示:
CommandLineParser parser = new();
var argument1 = parser.RegistArgeument("argument1", "mandate param 1st", true);
var argument2 = parser.RegistArgeument("argument2", "mandate param 2nd", true);
var command1 = parser.RegistCommand("-c|--command", "command is number", 50, new ValueParserInteger(0, 100));
var option1 = parser.RegistOption("-o|--option", "option is optional");
parser.Name = "Application Name";
parser.Parse(args);
parser.ShowHelpText();
# 
# Usage: Application Name
#
# Arguments:
# argument1    mandate param 1st
# argument2    mandate param 2nd
#
# Options:
# -o|--option    option is optional
#
# Commands:
# -c|--command <value>    command is number 
CommandLineParserクラスを継承したMyCommandLineを使用:
MyCommandLine parser = new();
parser.OnError(e => Console.Error.WriteLine(e.Message));
parser.Parse(args);
if(parser.HasHelp || parser.HasError)
{
    return;
}

問合せ先

使用方法や実装手順等、あるいは開発案件についてもご相談を承っていますので、お気軽にお問い合わせください。

マシフデジタルソリューション合同会社 https://www.massif.jp

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 208 7/20/2022