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
How to use with F#? #941
Comments
I don't think you've done anything wrong in the code example you've posted. It seems to work just fine for me when copy pasted into a new F# console project targeting What doesn't work for me is using the name of another function directly as a handler e.g.: let handler(test: string) =
Console.WriteLine test
[<EntryPoint>]
let main args =
let root = new RootCommand()
let option = new Option<string>("--test")
root.AddOption option
// Compiles just fine but test is null when the handler function gets called.
root.Handler <- CommandHandler.Create(handler)
root.Invoke args I'm assuming this is somehow caused by the implicit cast/conversion from You can get around this by either passing let handler(test: string) =
Console.WriteLine test
[<EntryPoint>]
let main args =
let root = new RootCommand()
let option = new Option<string>("--test")
root.AddOption option
root.Handler <- CommandHandler.Create(fun (test) -> handler test)
root.Invoke args Or defining a type to store your option values in. type Opt(test) =
member val Test: string = test
let handler(opt: Opt) =
Console.WriteLine opt.Test
[<EntryPoint>]
let main args =
let root = new RootCommand()
let option = new Option<string>("--test")
root.AddOption option
root.Handler <- CommandHandler.Create(handler)
root.Invoke args |
@twaalewijn thank you. |
Hi, I'm trying to use it in F#:
Handler is invoked, but
test
argument isnull
. What I'm doing wrong?The text was updated successfully, but these errors were encountered: