Exemplo n.º 1
0
Arquivo: main.go Projeto: suntong/lang
	cli.Helper
	Self *rootT       `cli:"c,config"usage:"config file" json:"-" parser:"jsonfile" dft:"fi.json"`
	Name string       `cli:"*n,name"usage:"Name (mandatory)"`
	Tag  string       `cli:"*t,tag"usage:"Tag used for record saving (mandatory)"`
	ID   string       `cli:"id"usage:"ID to use"`
	Fi   *clix.Reader `cli:"i,input"usage:"The source (or stdin if unspecified)"`
}

var root = &cli.Command{
	Name: "fi",
	Desc: "File input demo",
	Text: "File input demo with mandatory options",
	Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
	Fn:   fi,

	NumOption: cli.AtLeast(1),
}

func main() {
	//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 fi(ctx *cli.Context) error {
	ctx.JSON(ctx.RootArgv())
	ctx.JSON(ctx.Argv())
	fmt.Println()
Exemplo n.º 2
0
// install

type installT struct {
	Dir    string `cli:"dir" usage:"source code root dir" dft:"./"`
	Suffix string `cli:"suffix" usage:"source file suffix" dft:".go,.c,.s"`
	Out    string `cli:"o,out" usage:"output filename"`
}

var installCmd = &cli.Command{
	Name: "install",
	Desc: "Install the network application",
	Text: "Usage:\n  redo install [Options] package [package...]",
	Argv: func() interface{} { return new(installT) },
	Fn:   install,

	NumArg:      cli.AtLeast(1),
	CanSubRoute: true,
}

// func install(ctx *cli.Context) error {
// 	rootArgv := ctx.RootArgv().(*rootT)
// 	argv := ctx.Argv().(*installT)
// 	fmt.Printf("[install]:\n  %+v\n  %+v\n  %v\n", rootArgv, argv, ctx.Args())
// 	return nil
// }

////////////////////////////////////////////////////////////////////////////
// publish

type publishT struct {
	Dir    string `cli:"*d,dir" usage:"publish dir"`
Exemplo n.º 3
0
package main

import (
	"github.com/mkideal/cli"
)

var _ = app.Register(&cli.Command{
	Name: "install",
	Desc: "Install golang application",
	Text: "Usage:\n  gogo install [Options] package [package...]",
	Argv: func() interface{} { return new(installT) },
	Fn:   install,

	NumArg:      cli.AtLeast(1),
	CanSubRoute: true,
})

type installT struct {
	cli.Helper
	Dir    string `cli:"dir" usage:"source code root dir" dft:"./"`
	Suffix string `cli:"suffix" usage:"source file suffix" dft:".go,.c,.s"`
	Out    string `cli:"o,out" usage:"output filename"`
}

func install(ctx *cli.Context) error {
	argv := ctx.Argv().(*installT)
	ctx.String("%s: %v", ctx.Path(), jsonIndent(argv))
	ctx.String("Installing: %v\n", ctx.Args())
	return nil
}