Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module VersionOne.CommandLine
- type OptionBag = {
- storedCredsFile : string
- secretsFile : string
- } with
- static member Default = {
- storedCredsFile = "stored_credentials.json"
- secretsFile = "client_secrets.json"
- }
- let flagFuncs =
- Map [
- "-h", fun state -> failwith "Would display help here"
- ]
- let valueFuncs =
- Map [
- "--creds", fun state v -> {state with storedCredsFile = v}
- "--secrets", fun state v -> {state with secretsFile = v}
- ]
- let rec parseArgs' state = function
- | flag :: tail when flagFuncs.ContainsKey flag -> parseArgs' (flagFuncs.[flag] state) tail
- | flag :: v :: tail when valueFuncs.ContainsKey flag -> parseArgs' (valueFuncs.[flag] state v) tail
- | item :: tail -> failwith "Unexpected argument \"%s\" in command line"
- | [] -> state
- let parseArgs = parseArgs' OptionBag.Default
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement