dotnet / dotnet/command-line-api

F# app model

Open
#316 1 comment 0 reactions 0 assignees View on GitHub
Area-App Models
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

It would be nice to have F# parser like this Haskell library https://github.com/pcapriotti/optparse-applicative . I like that you can just pattern match the result. And it looks cool.

In F# it might look like the following when use (almost real code). Using notion from https://github.com/fsprojects/FSharpPlus

```f#
type Sample =
{ hello : string
quiet : bool
enthusiasm : int }

let currySample (hello : string) (quiet : bool) (enthusiasm : int) =
{ hello = hello
quiet = quiet
enthusiasm = enthusiasm }

let parser =
currySample
Option(Aliases [ "--hello"; "-h" ]
+ HelpDetail "description"
+ Argument ExactlyOne "TARGET")
<*> Option(Aliases [ "-q" ]
+ HelpDetail "description"
+ Argument Zero)
<*> Option(Aliases [ "--enthusiasm" ]
+ HelpDetail "description"
+ Argument ExactlyOne "INT")

let result : Sample = runParser parser "--hello Bob -q --enthusiasm 3"
```

To add in subcommand, Sample need to be a union and it should use alternative to combine parser https://github.com/pcapriotti/optparse-applicative#alternative

Problems:
1. Is there a genetic way to curry Record type? Or we may need to use Tuple.
2. How to fit Argument? Just by position could be fine. During config, the name of the Record field is not used.
...
...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.