{"id":13414901,"url":"https://github.com/natemcmaster/CommandLineUtils","last_synced_at":"2025-03-14T22:32:29.915Z","repository":{"id":37431976,"uuid":"100407304","full_name":"natemcmaster/CommandLineUtils","owner":"natemcmaster","description":"Command line parsing and utilities for .NET","archived":false,"fork":false,"pushed_at":"2024-03-30T06:09:54.000Z","size":7586,"stargazers_count":2209,"open_issues_count":10,"forks_count":254,"subscribers_count":64,"default_branch":"main","last_synced_at":"2024-10-29T15:36:23.601Z","etag":null,"topics":["command-line","dotnet","dotnet-core"],"latest_commit_sha":null,"homepage":"https://natemcmaster.github.io/CommandLineUtils/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/natemcmaster.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-15T18:32:24.000Z","updated_at":"2024-10-25T11:14:48.000Z","dependencies_parsed_at":"2023-02-18T20:15:37.842Z","dependency_job_id":"34eef5f4-b70d-4d2a-bcce-efd0ac49d249","html_url":"https://github.com/natemcmaster/CommandLineUtils","commit_stats":{"total_commits":903,"total_committers":107,"mean_commits":8.439252336448599,"dds":0.548172757475083,"last_synced_commit":"81199c7ec68367ea9612be55719dc1fe08f658da"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemcmaster%2FCommandLineUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemcmaster%2FCommandLineUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemcmaster%2FCommandLineUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemcmaster%2FCommandLineUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natemcmaster","download_url":"https://codeload.github.com/natemcmaster/CommandLineUtils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243658057,"owners_count":20326459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","dotnet","dotnet-core"],"created_at":"2024-07-30T21:00:39.551Z","updated_at":"2025-03-14T22:32:29.224Z","avatar_url":"https://github.com/natemcmaster.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","CLI","C\\#","dotnet","C#","框架, 库和工具","Tools","[Dotnet](https://dotnet.microsoft.com/)"],"sub_categories":["Tools","工具"],"readme":"CommandLineUtils\n================\n\n[![Build Status][ci-badge]][ci] [![Code Coverage][codecov-badge]][codecov]\n[![NuGet][nuget-badge] ![NuGet Downloads][nuget-download-badge]][nuget]\n\n[ci]: https://github.com/natemcmaster/CommandLineUtils/actions?query=workflow%3ACI+branch%3Amain\n[ci-badge]: https://github.com/natemcmaster/CommandLineUtils/workflows/CI/badge.svg\n[codecov]: https://codecov.io/gh/natemcmaster/CommandLineUtils\n[codecov-badge]: https://codecov.io/gh/natemcmaster/CommandLineUtils/branch/main/graph/badge.svg?token=l6uSsHZ8nA\n[nuget]: https://www.nuget.org/packages/McMaster.Extensions.CommandLineUtils/\n[nuget-badge]: https://img.shields.io/nuget/v/McMaster.Extensions.CommandLineUtils.svg?style=flat-square\n[nuget-download-badge]: https://img.shields.io/nuget/dt/McMaster.Extensions.CommandLineUtils?style=flat-square\n\nThis project helps you create command line applications using .NET.\nIt simplifies parsing arguments provided on the command line, validating\nuser inputs, and generating help text.\n\nThe **roadmap** for this project is [pinned to the top of the issue list](https://github.com/natemcmaster/CommandLineUtils/issues/).\n\n## Usage\n\nSee [documentation](https://natemcmaster.github.io/CommandLineUtils/) for API reference, samples, and tutorials.\nSee also [docs/samples/](./docs/samples/) for more examples, such as:\n\n - [Hello world](./docs/samples/helloworld/)\n - [Async console apps](./docs/samples/helloworld-async/)\n - [Structuring an app with subcommands](./docs/samples/subcommands/)\n - [Defining options with attributes](./docs/samples/attributes/)\n - [Interactive console prompts](./docs/samples/interactive-prompts/)\n - [Required options and arguments](./docs/samples/validation/)\n\n\n### Installing the library\n\nThis project is available as a [NuGet package][nuget].\n\n```\n$ dotnet add package McMaster.Extensions.CommandLineUtils\n```\n\n### Code\n`CommandLineApplication` is the main entry point for most console apps parsing. There are two primary ways to use this API, using the builder pattern and attributes.\n\n\n### Attribute API\n\n```c#\nusing System;\nusing McMaster.Extensions.CommandLineUtils;\n\npublic class Program\n{\n    public static int Main(string[] args)\n        =\u003e CommandLineApplication.Execute\u003cProgram\u003e(args);\n\n    [Option(Description = \"The subject\")]\n    public string Subject { get; } = \"world\";\n\n    [Option(ShortName = \"n\")]\n    public int Count { get; } = 1;\n\n    private void OnExecute()\n    {\n        for (var i = 0; i \u003c Count; i++)\n        {\n            Console.WriteLine($\"Hello {Subject}!\");\n        }\n    }\n}\n```\n\n### Builder API\n\n\n```c#\nusing System;\nusing McMaster.Extensions.CommandLineUtils;\n\nvar app = new CommandLineApplication();\n\napp.HelpOption();\n\nvar subject = app.Option(\"-s|--subject \u003cSUBJECT\u003e\", \"The subject\", CommandOptionType.SingleValue);\nsubject.DefaultValue = \"world\";\n\nvar repeat = app.Option\u003cint\u003e(\"-n|--count \u003cN\u003e\", \"Repeat\", CommandOptionType.SingleValue);\nrepeat.DefaultValue = 1;\n\napp.OnExecute(() =\u003e\n{\n    for (var i = 0; i \u003c repeat.ParsedValue; i++)\n    {\n        Console.WriteLine($\"Hello {subject.Value()}!\");\n    }\n});\n\nreturn app.Execute(args);\n```\n\n### Utilities\n\nThe library also includes other utilities for interaction with the console. These include:\n\n- `ArgumentEscaper` - use to escape arguments when starting a new command line process.\n    ```c#\n     var args = new [] { \"Arg1\", \"arg with space\", \"args ' with \\\" quotes\" };\n     Process.Start(\"echo\", ArgumentEscaper.EscapeAndConcatenate(args));\n    ```\n - `Prompt` - for getting feedback from users with a default answer.\n   A few examples:\n    ```c#\n    // allows y/n responses, will return false by default in this case.\n    // You may optionally change the prompt foreground and background color for\n    // the message.\n    Prompt.GetYesNo(\"Do you want to proceed?\", false);\n\n    // masks input as '*'\n    Prompt.GetPassword(\"Password: \");\n    ```\n - `DotNetExe` - finds the path to the dotnet.exe file used to start a .NET Core process\n    ```c#\n    Process.Start(DotNetExe.FullPathOrDefault(), \"run\");\n    ```\n\nAnd more! See the [documentation](https://natemcmaster.github.io/CommandLineUtils/) for more API, such as `IConsole`, `IReporter`, and others.\n\n## Getting help\n\nIf you need help with this project, please ...\n\n* read the documentation (https://natemcmaster.github.io/CommandLineUtils/),\n* look at the samples (https://github.com/natemcmaster/CommandLineUtils/tree/main/docs/samples),\n* review existing questions (many were answered already) (https://github.com/natemcmaster/CommandLineUtils/issues?q=label%3Aquestion+),\n* or use a programming Q\u0026A forum such as StackOverflow.com\n\n## Project origin and status\n\nThis is a fork of [Microsoft.Extensions.CommandLineUtils](https://github.com/aspnet/Common), which was [completely abandoned by Microsoft](https://github.com/aspnet/Common/issues/257). This project [forked in 2017](https://github.com/natemcmaster/CommandLineUtils/commit/f039360e4e51bbf8b8eb6236894b626ec7944cec) and continued to make improvements. From 2017 to 2021, over 30 contributors added new features and fixed bugs. As of 2022, the project has entered maintenance mode, so no major changes are planned. [See this issue for details on latest project status.](https://github.com/natemcmaster/CommandLineUtils/issues/485) This project is not abandoned -- I believe this library provides a stable API and rich feature set good enough for most developers to create command line apps in .NET -- but only the most critical of bugs will be fixed (such as security issues).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatemcmaster%2FCommandLineUtils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatemcmaster%2FCommandLineUtils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatemcmaster%2FCommandLineUtils/lists"}