Replies: 3 comments 4 replies
-
This just bit me! I just tried to convert this simple example into F#: open System
open Spectre.Console.Cli
type AddSettings() =
inherit CommandSettings()
[<CommandArgument(0, "[PROJECT]")>]
member val Project = "" with get, set
type AddPackageSettings() =
inherit AddSettings()
[<CommandArgument(0, "<PACKAGE_NAME>")>]
member val PackageName = "" with get, set
[<CommandOption("-v|--version <VERSION>")>]
member val Version = "" with get, set
type AddReferenceSettings() =
inherit AddSettings()
[<CommandArgument(0, "<PROJECT_REFERENCE>")>]
member val ProjectReference = "" with get, set
type AddPackageCommand() =
inherit Command<AddPackageSettings>()
override _.Execute (context, settings) = 0
type AddReferenceCommand() =
inherit Command<AddReferenceSettings>()
override _.Execute(context, settings) = 0
// Define a function to construct a message to print
let from whom =
sprintf "from %s" whom
[<EntryPoint>]
let main argv =
let message = from "F#" // Call the function
let app = CommandApp()
app.Configure(fun config ->
config.AddBranch<AddSettings>("add", fun add ->
add.AddCommand<AddPackageCommand>("package")
add.AddCommand<AddReferenceCommand>("reference")
)
)
app.Run(argv) Unfortunately, I keep running into this error: |
Beta Was this translation helpful? Give feedback.
-
I'm not very good at F#, but maybe @JamesRandall have some valuable input about this. |
Beta Was this translation helpful? Give feedback.
-
@bddckr caught me mid-typing.... awesome answer thank you! I've not looked at the CLI part of the F# bindings yet and never used them myself but would love suggestions from those of who have used it on what an idiomatic / pleasant approach might be. That feels a bit off topic here though so I've created a thread: |
Beta Was this translation helpful? Give feedback.
-
Spectre.Console uses extension methods to offer a fluent API. Because the extension methods use the same names that the properties use, F# users run into this compiler issue: dotnet/fsharp#11580.
As listed in the linked issue, there is no way to currently call the affected extension methods from F#. As a workaround one can call the extension method as a regular method, though that is quite unergonomic. Personally I've resorted to only utilize the properties for now.
Beta Was this translation helpful? Give feedback.
All reactions