Closed cschuchardt88 closed 2 weeks ago
Your attempt with --help
:
You are using a CommandLineBuilder. To use the built-in help options, call either UseHelp() or UseDefaults() (which itself calls UseHelp) on the CommandLineBuilder before building the parser from it.
Your attempt with ?
:
Note that ?
is different from -?
. -?
is one of the built-in help option aliases, but ?
is not.
Depending on what you want, you can declare ?
either as a help option alias, or as a custom command with the name ?
. If you want ?
just as another help option alias, pass it together with all other desired help option aliases as parameter to the UseHelp() method. (Attention: The aliases passed to UseHelp() replace the existing help option aliases, they are not added to them.)
Problem that I am having when I don't use RootCommand
It can't not even parse --help
or -?
; with UseHelp
or UseDefaults
. I believe the reason is because of RootCommand.ExecutableName
and RootCommand.ExecutablePath
is empty
or if used isn't on the line
that I am parsing. What I would like to know is how to display Help
info with the Command
class; I just want to add a new class HelpCommand : ICommandHandler
to able to type help
and display all the commands; also only show red
text in terminal image above (not the rest of the text that is displayed). I have tried looking through the source and couldn't find an easy way to do so.
Unfortunately, i am unable to follow your explanations :-( You say that "Problem that I am having when I don't use RootCommand It can't not even parse --help
or -?
". But System.CommandLine doesn't need a RootCommand to successfully parse the help options (demo: https://dotnetfiddle.net/XNX628)
I believe the reason is because of RootCommand.ExecutableName and RootCommand.ExecutablePath is empty or if used isn't on the line that I am parsing.
While i am not 100% certain, i doubt RootCommand.ExecutableName
and RootCommand.ExecutablePath
would be related to SCL being (un)able to parse the input string "--help" or "-?". The parser built from the CommandLineBuilder should successfully parse either input string, assuming the built-in help options have been actived via UseHelp() or UseDefaults(). But without being able to easily reproduce this on my end, i can't say for sure either way...
What I would like to know is how to display Help info with the Command class
I see two ways to do it. One way is to let the handler for the help command simply parse and invoke on a bespoke string featuring a help option. If your existing parser instance has these built-in help options activated, you could reuse it, i believe. Otherwise, let the help command create a new parser based off a new CommandLineBuilder that has the built-in help options activated.
The other way i see is letting the handler for the Help command do something similar to to what the SCL middleware for the built-in help options is doing: https://github.com/dotnet/command-line-api/blob/3e0db9e5830f2722645b9a576f80e3650b50f23a/src/System.CommandLine/Help/HelpResult.cs#L12-L23
also only show red text in terminal image above (not the rest of the text that is displayed).
Don't use UseParseErrorReporting() then, as it printing the help text is unfortunately hard-coded. Instead, inspect the parse result before calling Invoke/Async on it. Specifically look at its ParseResult.Errors
list. Each of the parse errors in this list provides the error message for that error in its ParseError.Message
property, which you can print out.
I am building a custom
console
prompt; however I keep getting error when a command is found or not. As you will see in the image below.How my app works:
I'm running my app as
MyApp.exe connect \\.\pipe\HelloWorld
then screen refreshes to appear as terminal on that computer. This would be my implementation ofIPC
for the program.Now this is the
prompt
(image) its not mypowershell
prompt; even though it looks like it. But still in myterminal
.