{"id":20796867,"url":"https://github.com/hkproj/copto","last_synced_at":"2025-09-05T16:06:10.534Z","repository":{"id":94993827,"uuid":"51694000","full_name":"hkproj/copto","owner":"hkproj","description":"C# library that incrementally parses command line arguments.","archived":false,"fork":false,"pushed_at":"2017-11-27T17:56:41.000Z","size":1152,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-11T23:55:11.595Z","etag":null,"topics":["command-line-parser","csharp","library"],"latest_commit_sha":null,"homepage":"","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/hkproj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-14T12:37:01.000Z","updated_at":"2024-01-01T00:53:37.000Z","dependencies_parsed_at":"2023-04-27T11:31:09.178Z","dependency_job_id":null,"html_url":"https://github.com/hkproj/copto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hkproj/copto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkproj%2Fcopto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkproj%2Fcopto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkproj%2Fcopto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkproj%2Fcopto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hkproj","download_url":"https://codeload.github.com/hkproj/copto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkproj%2Fcopto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273782306,"owners_count":25167130,"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","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-parser","csharp","library"],"created_at":"2024-11-17T16:29:18.352Z","updated_at":"2025-09-05T16:06:10.466Z","avatar_url":"https://github.com/hkproj.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Copto\n===================\n[![Build status](https://ci.appveyor.com/api/projects/status/s1ik7y6t076rt0k6?svg=true)](https://ci.appveyor.com/project/hkproj/copto)\n\nCopto is a C# library that lets you *incrementally* parse command line arguments. This means you don't have to create a huge class to hold all your options: parse/detect arguments only when you need them.\n\nFeatures\n-------------\nCopto can parse the following:\n\n- Switches: `/flag`, `-flag`, `--flag`\n- Boolean switches: `-flag=true`, `--flag=false`, `/flag:true`\n- Arguments with a single value: `--argument=value`, `/argument:value`, `--argument \"value\"`\n- Arguments with multiple values: `--include \"file1.h\" --include \"file2.h\" /include \"file3.h\"`\n\nQuick examples\n-------------\n#### Parse\nImport the library\n```csharp\nusing Copto;\n```\n\nStart by parsing the arguments and saving the result into a variable\n\n```csharp\nvar opts = Options.Parse(args);\n```\n\nYou can turn of case sensitivity\n```csharp\nvar opts = Options.Parse(args, new ParserOptions() { CaseSensitive = false });\n```\n\n#### Switches\n```csharp\nopts.Apply(new RuleSet()\n{\n\t// Use multiple aliases\n\t{ \"generate-report|genreport|gr\", () =\u003e operation = OperationType.GenerateReport }\n});\n```\n\n#### Boolean switches\n```csharp\nopts.Apply(new RuleSet()\n{\n\t// A null value is passed in case the user didn't specify \"true\" or \"false\" explicitly after the switch.\n\t// The following code activates the \"verbose mode\" even if the user only specified \"--verbose\" (or \"--v\")\n\t{ \"v|verbose\", (val) =\u003e verbose = val ?? true }\n});\n```\n\n#### Arguments with single value\n```csharp\nopts.Apply(new RuleSet()\n{\n\t{ \"o|output\", (val) =\u003e outputFile = val },\n\t// Integer value\n\t{ \"p|priority\",  delegate (int? val) { jobPriority = val; } }\n\t// Floating-point value\n\t{ \"s|seed\", delegate (float? val) { randomSeed = val; } }\n});\n```\n\n#### Arguments with multiple value\n```csharp\nopts.Apply(new RuleSet()\n{\n\t{ \"l|link|link-with\", (val) =\u003e linkWith.Add(val) }\n});\n```\n\n#### Specify argument position\nCopto allows you to detect arguments only if they are found at a specific position; this is very useful if the first argument is the type of operation to perform. For example a package management tool might have the following rules:\n```csharp\nopts.Apply(new RuleSet()\n{\n\t// Only if the argument is found at position \"0\" (first)\n\t{ \"update\", () =\u003e operation = OperationType.Update, 0 },\n\t{ \"install\", () =\u003e operation = OperationType.Install, 0 },\n\t{ \"delete\", () =\u003e operation = OperationType.Delete, 0 },\n\t// and here only if the argument is found at position \"1\" (second argument)\n\t{ \"package\", () =\u003e objectType = ObjectTypes.Package, 1 },\n\t{ \"system\", () =\u003e objectType = ObjectTypes.System, 1 },\n\t{ \"repository\", () =\u003e objectType = ObjectTypes.Repository, 1 }\n});\n```\n\nFull example\n-------------\nThe examples shows a simple report generation program. The program is launched with the following arguments:\n\n`./myprogram generate-report --days 4 --pi=\"3.14\" --use \"GOOG\" -add \"MSFT\" /use:\"YHOO\" /Add \"AMZN\" --o \"report.pdf\"`\n\nAs you can see there are integer values, floating point values and multiple arguments with the same name (but different format).\n\nParsing is easy and is done incrementally, which means the arguments are parsed only when needed:\n```csharp\nusing Copto;\n\nstatic Options Opts;\n\nstatic void Main(string[] args)\n{\n\t// Consider \"add\" and \"Add\" to be the same\n\tOpts = Options.Parse(args, new ParserOptions() { CaseSensitive = false });\n\tvar operation = OperationType.None;\n\n\t// The third, optional, parameter \"0\", indicates to only apply this rule if the argument is found in position \"0\".\n\tOpts.Apply(new RuleSet()\n\t{\n\t\t{ \"generate-report\", () =\u003e operation = OperationType.GenerateReport, 0 }\n\t});\n\n\tif (operation == OperationType.GenerateReport)\n\t\tGenerateReport();\n\telse\n\t\tConsole.WriteLine(\"No operation specified\");\n\n\n\tConsole.ReadLine();\n}\n\nstatic void GenerateReport()\n{\n\tvar generator = new ReportGenerator();\n\n\t// No need to re-parse the arguments. Use existing instance of the class.\n\tOpts.Apply(new RuleSet()\n\t{\n\t\t// Automatically parses numeric values and booleans\n\t\t{ \"days\", (days) =\u003e generator.Days = days },\n\t\t{ \"PI\", delegate (float? pi) { generator.PI = pi; } },\n\t\t{ \"use|add\", (use) =\u003e generator.Symbols.Add(use) },\n\t\t{ \"o|output\", (output) =\u003e generator.OutputFile = output }\n\t});\n\n\tgenerator.Generate();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkproj%2Fcopto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhkproj%2Fcopto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkproj%2Fcopto/lists"}