CuiLib 2.0.1

dotnet add package CuiLib --version 2.0.1                
NuGet\Install-Package CuiLib -Version 2.0.1                
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.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CuiLib --version 2.0.1                
#r "nuget: CuiLib, 2.0.1"                
#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.1

// Install CuiLib as a Cake Tool
#tool nuget:?package=CuiLib&version=2.0.1                

CuiLib

GitHub branch check runs GitHub License GitHub Release NuGet Downloads

.NETのCUIアプリケーション制作用ライブラリです。 コマンドライン引数を解析してオプションやパラメータなどの情報を取得します。

リリースログ:RelHistory.md

Usage

  • Command クラスをコマンドの単位として使用します
    • Command.ChildrenCommand クラスのインスタンスを登録することでサブコマンドを実装可能です
    • 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.Checkers;
using CuiLib.Commands;
using CuiLib.Logging;
using CuiLib.Options;

internal class Program
{
    private static void Main(string[] args)
    {
        var command = new ConcatCommand();
        // Invoke command with parameter analysis
        command.Invoke(args);
    }
}

// concat command class
internal 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.ValidSourceFile(),
            Required = true,
        };
        optionOutput = new SingleValueOption<FileInfo>('o', "out")
        {
            Description = "Output file",
            Checker = ValueChecker.ValidDestinationFile(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 when "-h" or "--help" option is specified
        if (optionHelp.Value)
        {
            WriteHelp(logger, null);
            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 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.

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
2.0.1 73 11/18/2024
2.0.0 63 11/18/2024
1.1.0 209 8/13/2023
1.0.1 169 7/6/2023
1.0.0 225 12/13/2022