commands/subcommands API is awkward
See original GitHub issueIs your feature request related to a problem? Please describe.
Building a CLI tool that takes has multiple commands (verbs) when processing a given data store.
manage-store add <add params>
manage-store list <list param>
manage-store delete <delete params>
Describe the solution you’d like
I’d like to just define the add
, list
and delete
classes decorated with something like the [Command]
(?) attribute. And perhaps a single entrypoint into a library-standardized dispatcher e.g.
public static void Main(string[] args)
{
// making up this name but you get the point
McMaster.Extensions.CommandLineUtils.RouteToCommand(args);
}
Describe alternatives you’ve considered
The current documentation just feels very awkward. It seems to offload CLI parsing and routing/dispatching back to user written code. Given that the concern is CLI parsing and routing, this should be handled from within the library itself.
On a related note, the documentation is unnecessarily complicated by cramming too many things into a single command/sub-command example.
IMHO, your root level readme.md should cover one quick example for regular CLIs (e.g. wget
) and another example for verbs/commands based CLIs (like dotnet <verbs>
).
Additional context
Don’t really care about the builder API if it matters. Great tool by the way - thanks!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
@natemcmaster seems like you already have this functionality and it’s actually quite simple and well designed. Documentation is definitely misleading/confusing about the minimal ‘magic’ / assumptions needed to get this working.
Program.cs
AddCmd.cs (DeleteCmd is similar)
Regarding
System.Commandline
that would be even better. IMHO as long as ‘console application’ is a supported flavor, this sort of CLI parsing should be right in the .net standard itself. Imagine having ASP.NET as a supported programming model but leavingControllers
or the router entirely as community effort libraries. So your work is very much appreciated!This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 7 days.