-
-
Notifications
You must be signed in to change notification settings - Fork 260
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
commands/subcommands API is awkward #116
Comments
Slightly off-topic but still related: I noticed that you've got |
The samples/Subcommands/Program.cs file you pointed to is not a representative sample. I recommend taking a look at these instead and tell me then if you think the API is still awkward. https://github.com/natemcmaster/CommandLineUtils/blob/master/samples/Subcommands/Inheritance.cs Agree, we should cleanup the samples and docs folder. They've grown organically and separately. Would be good to unify. |
Re your side note: I've seen https://github.com/commandlineparser/commandline, but there are no plans to unify with them. I'm hoping at some point to unify this library with System.CommandLine, when/if that lands. |
@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 using McMaster.Extensions.CommandLineUtils;
namespace DataStore
{
[Command(ThrowOnUnexpectedArgument = false)]
[Subcommand("add", typeof(AddCmd))]
[Subcommand("delete", typeof(DeleteCmd))]
[HelpOption("--help")]
class Program
{
public static void Main(string[] args)
{
CommandLineApplication.Execute<Program>(args);
}
}
} AddCmd.cs (DeleteCmd is similar) using McMaster.Extensions.CommandLineUtils;
using System;
using System.ComponentModel.DataAnnotations;
namespace DataStore
{
[HelpOption("--help")]
public class AddCmd
{
[Required]
[Option("--addParam1", Description = "1st parameter for add")]
public string AddParam1 { get; set; }
[Required]
[Option("--addParam2", Description = "2nd parameter for add")]
public MyEnum AddParam2 { get; set; }
public void OnExecute()
{
// do work, AddParam1 and AddParam2 (enum auto-parsed) available here
}
}
} Regarding |
Ok, glad you found what you needed. I'll work on cleaning up docs to make it more discoverable. Of course, I'm happy to take contributions, too.
There be dragons, my friend. There is a surprisingly contentious history on this matter. |
What is |
👋 Hey @jerriep... Letting you know, |
@jerriep it's project that's been brewing on the .NET team for a while. I helped earlier this year on some of the early versions. I don't think there is a target date yet for making it a real thing. See dotnet/corefxlab#2245 (comment) |
Thanks Nate! I have subscribed to that issue to keep track of the progress. |
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. |
Is 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.
Describe the solution you'd like
I'd like to just define the
add
,list
anddelete
classes decorated with something like the[Command]
(?) attribute. And perhaps a single entrypoint into a library-standardized dispatcher e.g.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 (likedotnet <verbs>
).Additional context
Don't really care about the builder API if it matters. Great tool by the way - thanks!
The text was updated successfully, but these errors were encountered: