本文整理汇总了Golang中launchpad/net/juju-core/cmd.Command类的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunCommandInDir
// RunCommandInDir works like RunCommand, but runs with a context that uses dir.
func RunCommandInDir(c *C, com cmd.Command, args []string, dir string) (*cmd.Context, error) {
if err := InitCommand(com, args); err != nil {
return nil, err
}
var context = ContextForDir(c, dir)
return context, com.Run(context)
}
示例2: InitCommand
// InitCommand will create a new flag set, and call the Command's SetFlags and
// Init methods with the appropriate args.
func InitCommand(c cmd.Command, args []string) error {
f := NewFlagSet()
c.SetFlags(f)
if err := cmd.ParseArgs(c, f, args); err != nil {
return err
}
return c.Init(f.Args())
}
示例3: testInit
// testInit checks that a command initialises correctly
// with the given set of arguments.
func testInit(c *C, com cmd.Command, args []string, errPat string) {
err := com.Init(newFlagSet(), args)
if errPat != "" {
c.Assert(err, ErrorMatches, errPat)
} else {
c.Assert(err, IsNil)
}
}
示例4: helpText
func helpText(command cmd.Command, name string) string {
buff := &bytes.Buffer{}
info := command.Info()
info.Name = name
f := gnuflag.NewFlagSet(info.Name, gnuflag.ContinueOnError)
command.SetFlags(f)
buff.Write(info.Help(f))
return buff.String()
}
示例5: runCommand
func runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
errc = make(chan error, 1)
opc = make(chan dummy.Operation, 200)
dummy.Listen(opc)
go func() {
// signal that we're done with this ops channel.
defer dummy.Listen(nil)
err := coretesting.InitCommand(com, args)
if err != nil {
errc <- err
return
}
err = com.Run(cmd.DefaultContext())
errc <- err
}()
return
}
示例6: initCmd
func initCmd(c cmd.Command, args []string) error {
f := gnuflag.NewFlagSet("", gnuflag.ContinueOnError)
f.SetOutput(ioutil.Discard)
return c.Init(f, args)
}