Skip to content

Instantly share code, notes, and snippets.

@bleis-tift
Created January 14, 2018 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleis-tift/84ea0e705daff0d5237e457ba939209b to your computer and use it in GitHub Desktop.
Save bleis-tift/84ea0e705daff0d5237e457ba939209b to your computer and use it in GitHub Desktop.
type CommandInfo =
{ Names: string[]
Summary: string
Syntax: string
Help: string option }
type CommandWrapper(info: CommandInfo, proc: string -> unit) =
inherit Command()
override __.Names = info.Names
override __.Summary = info.Summary
override __.Syntax = info.Syntax
override __.Help =
match info.Help with
| Some help -> help
| None -> base.Help
override __.Process(args) = proc args
[<Sealed; Command>]
type MultiCommandWrapper(info: CommandInfo, commands: Command list) =
inherit MultiCommand()
do
for cmd in cmds do
base.AddCommand(cmd)
override __.Names = info.Names
override __.Summary = info.Summary
override __.Syntax = info.Syntax
override __.Help =
match info.Help with
| Some help -> help
| None -> base.Help
let helloWorldCmd =
let info =
{ Names = [|"bbbcmd"|]
Summary = "aaa bbb ccc"
Syntax = "ddd eee fff"
Help = Some "help help help" }
CommandWrapper(info, args -> Log.Info("hello world from bbbcmd"))
let myCommand =
let info =
{ Names = [|"aaacmd"|]
Summary = "aaaaaaaaaaa"
Syntax = "bbbbbbbbbbb"
Help = Some "cccccccccccccc" }
MultiCommandWrapper(info, [helloWorldCmd])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment