C
C#14mo ago
Thinker

❔ 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
Chiyoko_S
Chiyoko_S14mo ago
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?
Thinker
Thinker14mo ago
eh, it works fine
Chiyoko_S
Chiyoko_S14mo ago
I used to use it but moved away to Spectre, but I digress
Thinker
Thinker14mo ago
Yeah I've been given this recommendation from someone on the System.CommandLine repo, I'm gonna have to investigate it
Chiyoko_S
Chiyoko_S14mo ago
Thinker
Thinker14mo ago
Spectre is nice although I prefer how much more extensive System.CommandLine is Granted it's still in beta
Chiyoko_S
Chiyoko_S14mo ago
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 >.>
Thinker
Thinker14mo ago
I'd be happy if it was merged into the BCL
Chiyoko_S
Chiyoko_S14mo ago
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...
Chiyoko_S
Chiyoko_S14mo ago
Yeah. It's something I feel like quite a gap that the current BCL is missing, something that does command line handling and stuffs
Thinker
Thinker14mo ago
It's kind of funny how many CLI libraries there are
Chiyoko_S
Chiyoko_S14mo ago
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
Thinker
Thinker14mo ago
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
Chiyoko_S
Chiyoko_S14mo ago
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
Accord
Accord14mo ago
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.