❔ Default command in System.CommandLine
I'm using System.CommandLine for a little CLI, and I want two commands:
compile
and run
. What I want is for the user to be able to just do myapp path/to/some.file
which would invoke compile
by default, but also be able to do myapp run path/to/some.file
, in a similar vein to how dotnet path/to/some.file
is just dotnet exec path/to/some.file
. How do you do this?15 Replies
isn't System.Commandline, like, pretty crap at the current state
can't you just register the same handler for both the root command and the subcommand?
eh, it works fine
I used to use it but moved away to Spectre, but I digress
Yeah I've been given this recommendation from someone on the System.CommandLine repo, I'm gonna have to investigate it
How to define commands in System.CommandLine
Learn how to define commands, options, and arguments by using the System.Commandline library.
Spectre is nice although I prefer how much more extensive System.CommandLine is
Granted it's still in beta
I see
Yeah, something that makes me stop using it now is that I think there's some work going on in the main dotnet/runtime repo in the same namespace
so I'm afraid if things will massively change compared to the package already released now
which is, imo, not a bad thing, but I don't want to rewrite stuffs afterwards >.>
I'd be happy if it was merged into the BCL
GitHub
[API proposal]: System.CommandLine APIs · Issue #68578 · dotnet/run...
Updated version: #68578 (comment) Old version: Background and motivation System.CommandLine is finalizing GA and is thus looking for a final design review prior to V1. There have been significant c...
Yeah. It's something I feel like quite a gap that the current BCL is missing, something that does command line handling and stuffs
It's kind of funny how many CLI libraries there are
I mean, it's not necessarily a bad thing, because competition and all
I find it somewhat funny how .NET people always ask "why dis is not in the BCL already ree" compared to Node / Python where people never seem to mind adding all sorts of dependencies for all the things
Not that it's bad. I get why it is the case, just interesting how people think differently
I mean, .NET is kind of spoiled in terms of its BCL
It's massive and has a ton of things out-of-the-box
Yeah it's very nice having things out of the box
and something that has good guarantees about its future, unlike many open source libraries run by people in the free time & may not necessarily be maintained for long
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.