CJF.CommandLine 1.30.702.20526

There is a newer version of this package available.
See the version list below for details.
dotnet add package CJF.CommandLine --version 1.30.702.20526
                    
NuGet\Install-Package CJF.CommandLine -Version 1.30.702.20526
                    
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="CJF.CommandLine" Version="1.30.702.20526" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CJF.CommandLine" Version="1.30.702.20526" />
                    
Directory.Packages.props
<PackageReference Include="CJF.CommandLine" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CJF.CommandLine --version 1.30.702.20526
                    
#r "nuget: CJF.CommandLine, 1.30.702.20526"
                    
#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.
#:package CJF.CommandLine@1.30.702.20526
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CJF.CommandLine&version=1.30.702.20526
                    
Install as a Cake Addin
#tool nuget:?package=CJF.CommandLine&version=1.30.702.20526
                    
Install as a Cake Tool

主控台指令行介面(Command Line Interface) For .Net Core

使用方法:

Host.CreateDefaultBuilder(args)
    .UseConsoleLifetime(opts => opts.SuppressStatusMessages = true)
    // .UseCommandLine(). // No use prompt
    .UseCommandLine(opts => opts.Prompt = $"{CurrentUser}\x1B[93m#\x1B[39m ", AppendCommands)
    .Build();

命令設定方式:

使用自訂屬性 CommandAttribute 設定,如:

[Command("quit")]
static void CLI_Quit()
{
    Environment.Exit(0);
}

函示格式定義

欲綁定 CommandAttribute 自訂屬性的函示定義格式如下:

static void CLI_Mathod1() { /*...*/ }
static void CLI_Mathod2(CliCenter cli) { /*...*/ }
static void CLI_Mathod3(CliCenter cli, params string[] args) { /*...*/ }
static void CLI_Mathod3(params string[] args) { /*...*/ }
static void CLI_Mathod3(CommandAttribute cmd, params string[] args) { /*...*/ }
static void CLI_Mathod3(CliCenter cli, CommandAttribute cmd, params string[] args) { /*...*/ }

以上六種方式

以下為使用範例:

#region CLI : Show Command Help - 2 Parameters: CliCenter, string[]
[Command("show", "顯示內部資料。")]
[Command("echo", "顯示輸入的文字。", "show")]
static void CLI_HasSubCommand(CliCenter cli, params string[] args)
{
    if (args[0] == "do-exec")
        args = args[1..];
    Console.WriteLine($"> 輸入 \"\x1B[96m{cli.AnalyzeToFullCommand(string.Join(" ", args))} ?\x1B[39m\" 顯示子指令清單與說明");
    Console.WriteLine();
}
#endregion

#region CLI : quit - No Parameter
[Command("quit", "關閉本程式")]
[Command("quit", "關閉本程式", "do-exec", Tag = "config")]
static void CLI_Quit()
{
    Environment.Exit(0);
}
#endregion

#region CLI : exit - 1 Parameter: CliCenter
[Command("exit", "離開設定模式", Tag = "config")]
static void CLI_Exit(CliCenter cli)
{
    if (string.IsNullOrEmpty(cli.UseTag)) return;
    cli.UseTag = "";
    cli.Prompt = $"{CurrentUser}\x1B[93m#\x1B[39m ";
    cli.HistoryPool = "default";
}
#endregion

#region CLI : config - 1 Parameter: CliCenter
[Command(MODE_CONFIG, "進入設定模式")]
static void CLI_ConfigMode(CliCenter cli)
{
    cli.UseTag = "config";
    cli.Prompt = $"{CurrentUser}(\x1B[96m{cli.UseTag}\x1B[39m)\x1B[93m#\x1B[39m ";
    Console.WriteLine();
}
#endregion

#region CLI : show echo [String] - 1 Parameter: string[]
[Command(CliCenter.STRING_REGEX, "如包含空白,請用單或雙引號。", "show echo", IsRegular = true, RegularHelp = "[String]")]
static void CLI_Echo(params string[] args)
{
    Console.WriteLine($"> Echo: \"\x1B[92m{args[2]}\x1B[39m\"");
    Console.WriteLine();
}
#endregion
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.37.906 279 9/18/2024
1.35.810 177 7/4/2024
1.34.795 141 6/28/2024
1.33.752 224 7/10/2023
1.33.740 221 7/6/2023
1.32.725 232 6/27/2023
1.31.710 204 6/5/2023
1.30.702.20526 243 5/26/2023