CuiLib 1.1.0

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

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

CuiLib

.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.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 Compatible and additional computed target framework versions.
.NET 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 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.

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.1.0 178 8/13/2023
1.0.1 148 7/6/2023
1.0.0 203 12/13/2022