Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【开源项目】commandline #774

Closed
tonyqus opened this issue Dec 9, 2024 · 1 comment
Closed

【开源项目】commandline #774

tonyqus opened this issue Dec 9, 2024 · 1 comment

Comments

@tonyqus
Copy link
Member

tonyqus commented Dec 9, 2024

https://github.com/commandlineparser/commandline
4.6k stars, nuget 142M下载量

@gaufung gaufung changed the title 【开源项目】开源命令行程序框架 【开源项目】commandline Dec 24, 2024
@gaufung
Copy link
Collaborator

gaufung commented Dec 24, 2024

Commandline 是一个开源包,用来完成命令行应用程序中的参数,它有如下特色

  1. 支持 .NET Framework 4+, .NET Standard, Mono.NET Core
  2. 没有其他库的依赖
  3. 只有一个重要函数 CommandLine.Parser.Default.ParseArguments(...) 来解析参数请求
  4. 支持各种命令行参数形式
class Program
{
        public class Options
        {
            [Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
            public bool Verbose { get; set; }
        }

        static void Main(string[] args)
        {
            Parser.Default.ParseArguments<Options>(args)
                   .WithParsed<Options>(o =>
                   {
                       if (o.Verbose)
                       {
                           Console.WriteLine($"Verbose output enabled. Current Arguments: -v {o.Verbose}");
                       }
                       else
                       {
                           Console.WriteLine($"Current Arguments: -v {o.Verbose}");
                       }
                   });
        }
 }

@gaufung gaufung closed this as completed Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants