zijian666.CommandLineExtensions
1.0.0-beta
This is a prerelease version of zijian666.CommandLineExtensions.
dotnet add package zijian666.CommandLineExtensions --version 1.0.0-beta
NuGet\Install-Package zijian666.CommandLineExtensions -Version 1.0.0-beta
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="zijian666.CommandLineExtensions" Version="1.0.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="zijian666.CommandLineExtensions" Version="1.0.0-beta" />
<PackageReference Include="zijian666.CommandLineExtensions" />
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 zijian666.CommandLineExtensions --version 1.0.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: zijian666.CommandLineExtensions, 1.0.0-beta"
#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 zijian666.CommandLineExtensions@1.0.0-beta
#: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=zijian666.CommandLineExtensions&version=1.0.0-beta&prerelease
#tool nuget:?package=zijian666.CommandLineExtensions&version=1.0.0-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
zijian666.Commandline.Extensions
介绍
基于官方组件 System.CommandLine 扩展
更新日志
安装教程
项目示例
功能说明
先定义一个命令对象
//[Description("打个招呼吧")]
[CommandLineAction("hello", Alias = ["hi"], Description = "打个招呼吧")]
internal class Hello //: ICommandLineAction
{
[Option(Alias = ["n"])]
[Description("你的名字")]
//[Required]
public required string Name { get; set; }
[Option(Alias = ["j"])]
[Description("你的职业")]
public string[]? Job { get; set; }
public void Execute()
{
if (Job?.Length is 0 or null)
{
Console.WriteLine($"你好, {Name}!");
}
else
{
Console.WriteLine($"你好, {string.Join("/", Job)} {Name}!");
}
}
}
注册到 命令行
var root = new RootCommand();
root.BindCommand<TestAction>(); // 绑定动作到根命令
root.AddCommand<Hello>(); // 添加子命令
// 同步或异步执行
root.Invoke();
//await root.InvokeAsync();
效果
> demo
Description:
用法:
demo [command] [options]
选项:
--test 打印测试信息
-?, -h, --help Show help and usage information
--version 显示版本信息
命令:
hello, hi 打个招呼吧
> demo hi -?
Description:
打个招呼吧
用法:
demo hello [options]
选项:
-n, --name <name> (REQUIRED) 你的名字
-j, --job <job> (REQUIRED) 你的职业
-?, -h, --help Show help and usage information
> demo hi -n zijian666 -j 程序员 -j 机修工
你好, 程序员/机修工 zijian666!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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.
-
net8.0
- System.CommandLine (>= 2.0.0-rc.1.25451.107)
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.0.0-beta | 185 | 10/5/2025 |
UPLOGS.md