CJF.CommandLine
1.30.702.20526
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 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" />
<PackageReference Include="CJF.CommandLine" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=CJF.CommandLine&version=1.30.702.20526
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
主控台指令行介面(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 | Versions 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.
-
net6.0
- Microsoft.Extensions.Hosting (>= 7.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.