Skip to content

Instantly share code, notes, and snippets.

@suntong
Created December 4, 2016 22:37
Show Gist options
  • Save suntong/fdd74049660315e54fa72ecb5fd2f04e to your computer and use it in GitHub Desktop.
Save suntong/fdd74049660315e54fa72ecb5fd2f04e to your computer and use it in GitHub Desktop.
// -*- go -*-
////////////////////////////////////////////////////////////////////////////
// Program: dump
// Purpose: dump assistant program
////////////////////////////////////////////////////////////////////////////
package main
import (
"fmt"
"github.com/mkideal/cli"
clix "github.com/mkideal/cli/ext"
"os"
)
////////////////////////////////////////////////////////////////////////////
// dump
type rootT struct {
cli.Helper
Filei *clix.Reader `cli:"*i,input"usage:"The file to dump from (mandatory)"`
Fileo *clix.Writer `cli:"o,output"usage:"The dump output (default: .dump file of input)"`
ID bool `cli:"id"usage:"Dump ID as well"`
}
var root = &cli.Command{
Name: "dump",
Desc: "dump assistant program",
Text: "Swiss-army assistant toolkit",
Argv: func() interface{} { return new(rootT) },
Fn: dump,
NumArg: cli.AtLeast(1),
}
func main() {
cli.SetUsageStyle(cli.ManualStyle) // up-down, for left-right, use NormalStyle
//NOTE: You can set any writer implements io.Writer
// default writer is os.Stdout
if err := cli.Root(root).Run(os.Args[1:]); err != nil {
fmt.Fprintln(os.Stderr, err)
}
fmt.Println("")
}
func dump(ctx *cli.Context) error {
ctx.JSON(ctx.RootArgv())
ctx.JSON(ctx.Argv())
fmt.Println()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment