Skip to content
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

Use System.CommandLine for CLI parsing #888

Merged
merged 8 commits into from
Apr 7, 2022

Conversation

baronfel
Copy link
Contributor

@baronfel baronfel commented Feb 12, 2022

I've been using S.CL a lot on the .NET SDK, and while it's not quite as feature-ful as Argu it is way faster, and our use of Argu isn't super complex anyway.

S.CL also encourages a layering of options such that I can put together some middleware to take care of different slices of the startup code (like logging configuration) and get it out of the way of the main app startup code.

Anyway, seems to be working locally. Help output for the CLI looks good:

Description:
  An F# LSP server implementation

Usage:
  fsautocomplete [options]

Options:
  -v, --debug, --verbose                                 Enable verbose logging. This is equivalent to --log-level debug.
  --attach-debugger                                      Launch the system debugger and break immediately
  -l, --log-file, --logfile <log-file>                   Send log output to specified file.
  --filter <filter>                                      Filter logs by category. The category can be seen in the logs inside []. For example: [Compiler].
  --wait-for-debugger                                    Stop execution on startup until an external debugger to attach to this process
  --host-pid, --hostPID <host-pid>                       Process ID of the host process.
  --background-service-enabled                           Enable running typechecking services in a background process. Enables various performance optimizations.
  --project-graph-enabled                                Enable MSBuild Graph workspace loading. Should be faster than the default, but is experimental.
  --log-level <Debug|Error|Fatal|Information|Verbose|Warning>  Set the log verbosity to a specific level.
  --version                                              Show version information
  -?, -h, --help                                         Show help and usage information

One thing that's useful is testing the parsing of your CLI app, which you can do with the [parse] directive. This lets you see how the command would be parsed so you can make sure that nothing erroneous happens

17:02:47 ❯ dotnet run -- [parse] --filter Compiler LSP FileSystem "a log source with spaces"
[ fsautocomplete [ --filter <Compiler> <LSP> <FileSystem> <a log source with spaces> ] ]

Here, the command fsautocomplete is given the option --filter, and that option has 4 arguments. This is nicer (and more capable!) parsing code than we had for filters before IMO.

@baronfel baronfel marked this pull request as ready for review February 13, 2022 02:54
@baronfel
Copy link
Contributor Author

baronfel commented Apr 7, 2022

As part of this I dropped the --host-pid parameter, since it was not used in the codebase anymore

@baronfel baronfel merged commit 28c4b5c into ionide:main Apr 7, 2022
@baronfel baronfel deleted the system.commandline branch April 7, 2022 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant