CuiLib 2.0.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package CuiLib --version 2.0.0
NuGet\Install-Package CuiLib -Version 2.0.0
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="CuiLib" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CuiLib --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CuiLib, 2.0.0"
#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 CuiLib as a Cake Addin #addin nuget:?package=CuiLib&version=2.0.0 // Install CuiLib as a Cake Tool #tool nuget:?package=CuiLib&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CuiLib
.NETのCUIアプリケーション制作用ライブラリです。 コマンドライン引数を解析してオプションやパラメータなどの情報を取得します。
リリースログ:RelHistory.md
Usage
Command
クラスをコマンドの単位として使用しますCommand.Children
にCommand
クラスのインスタンスを登録することでサブコマンドを実装可能ですCommand.OnExecution()
またはCommand.OnExecutionAsync()
をオーバーライドすることでコマンドの処理内容を記述できますCommand.WriteHelp(Logger)
で標準的なヘルプコマンドを出力できます
Option
クラスをオプションとして使用しますFlagOption
では--help
のようなフラグとしてのオプションを扱いますSingleValueOption<T>
では-i hoge.txt
のように値を取るオプションを扱いますMultipleValueOption<T>
では-i hoge.txt -i fuga.txt
のように複数の値を取るオプションを扱いますIValueConverter<T>
インターフェイスで文字列からの値の変換をカスタマイズできますIValueChecker<T>
インターフェイスで値のエラーチェックをカスタマイズできます
Parameter<T>
ではパラメータ引数を扱いますIValueConverter<T>
インターフェイスで文字列からの値の変換をカスタマイズできますIValueChecker<T>
インターフェイスで値のエラーチェックをカスタマイズできます
以下の例は, -i
(--in
) オプションで1つ以上指定されたテキストファイルを順に結合して -o
(--out
) オプションで指定されたファイルに出力するコマンドの実装です。
Command.Invoke(string[])
でアプリケーション引数をそのまま引数解析して ConcatCommand
の処理を実行します。
using System;
using System.Collections.Generic;
using System.IO;
using CuiLib.Commands;
using CuiLib.Loggers;
using CuiLib.Options;
static void Main(string[] args)
{
var command = new ConcatCommand();
// Invoke command with parameter analysis
command.Invoke(args);
}
// concat command class
class ConcatCommand : Command
{
private readonly FlagOption optionHelp;
private readonly MultipleValueOption<FileInfo> optionInput;
private readonly SingleValueOption<FileInfo> optionOutput;
public ConcatCommand() : base("concat")
{
Description = "concat texts";
// Define options
optionHelp = new FlagOption('h', "help")
{
Description = "Display help",
};
optionInput = new MultipleValueOption<FileInfo>('i', "in")
{
Description = "Input files",
Checker = ValueChecker.VerifySourceFile(),
Required = true,
};
optionOutput = new SingleValueOption<FileInfo>('o', "out")
{
Description = "Output file",
Checker = ValueChecker.VerifyDestinationFile(false, true),
Required = true,
};
// Add options
Options.Add(optionHelp);
Options.Add(optionInput);
Options.Add(optionOutput);
}
protected override void OnExecution()
{
// create logger
var logger = new Logger()
{
ConsoleStdoutLogEnabled = true,
};
// show help if "-h" or "--help" option available
if (optionHelp.ValueAvailable)
{
WriteHelp(logger);
return;
}
FileInfo[] input = optionInput.Value; // "-i" or "--in" value
FileInfo output = optionOutput.Value; // "-o" or "--out" value
using StreamWriter writer = output.CreateText();
// output each files
foreach (FileInfo currentInput in input)
{
using StreamReader reader = currentInput.OpenText();
while (!reader.EndOfStream)
{
string? line = reader.ReadLine();
writer.WriteLine(line);
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 is compatible. 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. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- IndexRange (>= 1.0.3)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Nullable (>= 1.3.1)
- System.Linq.Async (>= 6.0.1)
- System.Memory (>= 4.6.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.0)
-
.NETStandard 2.1
- Nullable (>= 1.3.1)
- System.Linq.Async (>= 6.0.1)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.0)
-
net6.0
- System.Linq.Async (>= 6.0.1)
-
net7.0
- System.Linq.Async (>= 6.0.1)
-
net8.0
- System.Linq.Async (>= 6.0.1)
-
net9.0
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.