当前位置: 首页>>代码示例>>Golang>>正文


Golang cmd.Command类代码示例

本文整理汇总了Golang中github.com/juju/cmd.Command的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Command类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RunCommand

// RunCommand runs a command with the specified args.  The returned error
// may come from either the parsing of the args, the command initialisation, or
// the actual running of the command.  Access to the resulting output streams
// is provided through the returned context instance.
func RunCommand(c *gc.C, com cmd.Command, args ...string) (*cmd.Context, error) {
	if err := InitCommand(com, args); err != nil {
		return nil, err
	}
	var context = Context(c)
	return context, com.Run(context)
}
开发者ID:wwitzel3,项目名称:juju-cmd,代码行数:11,代码来源:cmd.go

示例2: RunCommandInDir

// RunCommandInDir works like RunCommand, but runs with a context that uses dir.
func RunCommandInDir(c *gc.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)
}
开发者ID:wwitzel3,项目名称:juju-cmd,代码行数:8,代码来源:cmd.go

示例3: RunCommand

// RunCommand runs the command and returns channels holding the
// command's operations and errors.
func RunCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
	if ctx == nil {
		panic("ctx == nil")
	}
	errc = make(chan error, 1)
	opc = make(chan dummy.Operation, 200)
	dummy.Listen(opc)
	go func() {
		defer func() {
			// signal that we're done with this ops channel.
			dummy.Listen(nil)
			// now that dummy is no longer going to send ops on
			// this channel, close it to signal to test cases
			// that we are done.
			close(opc)
		}()

		if err := coretesting.InitCommand(com, args); err != nil {
			errc <- err
			return
		}

		errc <- com.Run(ctx)
	}()
	return
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:testing.go

示例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()
}
开发者ID:klyachin,项目名称:juju,代码行数:9,代码来源:main_test.go

示例5: RegisterDeprecated

func (r *stubRegistry) RegisterDeprecated(subcmd cmd.Command, check cmd.DeprecationCheck) {
	r.stub.AddCall("RegisterDeprecated", subcmd, check)
	r.stub.NextErr() // pop one off

	r.names = append(r.names, subcmd.Info().Name)
	for _, name := range subcmd.Info().Aliases {
		r.names = append(r.names, name)
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:commands_test.go

示例6: Register

func (r *stubRegistry) Register(subcmd cmd.Command) {
	r.stub.AddCall("Register", subcmd)
	r.stub.NextErr() // pop one off

	r.names = append(r.names, subcmd.Info().Name)
	for _, name := range subcmd.Info().Aliases {
		r.names = append(r.names, name)
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:commands_test.go

示例7: RunCommand

// RunCommand runs a command with the specified args.  The returned error
// may come from either the parsing of the args, the command initialisation, or
// the actual running of the command.  Access to the resulting output streams
// is provided through the returned context instance.
func RunCommand(c *gc.C, com cmd.Command, args ...string) (*cmd.Context, error) {
	var context = Context(c)
	if err := InitCommand(com, args); err != nil {
		if err != nil {
			fmt.Fprintf(context.Stderr, "error: %v\n", err)
		}
		return context, err
	}
	return context, com.Run(context)
}
开发者ID:bac,项目名称:juju,代码行数:14,代码来源:cmd.go

示例8: checkHelp

func (s *BaseActionSuite) checkHelp(c *gc.C, subcmd cmd.Command) {
	ctx, err := coretesting.RunCommand(c, s.command, subcmd.Info().Name, "--help")
	c.Assert(err, gc.IsNil)

	expected := "(?sm).*^usage: juju action " +
		regexp.QuoteMeta(subcmd.Info().Name) +
		` \[options\] ` + regexp.QuoteMeta(subcmd.Info().Args) + ".+"
	c.Check(coretesting.Stdout(ctx), gc.Matches, expected)

	expected = "(?sm).*^purpose: " + regexp.QuoteMeta(subcmd.Info().Purpose) + "$.*"
	c.Check(coretesting.Stdout(ctx), gc.Matches, expected)

	expected = "(?sm).*^" + regexp.QuoteMeta(subcmd.Info().Doc) + "$.*"
	c.Check(coretesting.Stdout(ctx), gc.Matches, expected)
}
开发者ID:pmatulis,项目名称:juju,代码行数:15,代码来源:package_test.go

示例9: runCommand

func runCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
	if ctx == nil {
		panic("ctx == nil")
	}
	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(ctx)
		errc <- err
	}()
	return
}
开发者ID:rogpeppe,项目名称:juju,代码行数:22,代码来源:cmd_test.go

示例10: 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 := f.Parse(c.AllowInterspersedFlags(), args); err != nil {
		return err
	}
	return c.Init(f.Args())
}
开发者ID:wwitzel3,项目名称:juju-cmd,代码行数:10,代码来源:cmd.go

示例11: checkHelp

func (s *BaseBackupsSuite) checkHelp(c *gc.C, subcmd cmd.Command) {
	ctx, err := jujutesting.RunCommand(c, s.command, subcmd.Info().Name, "--help")
	c.Assert(err, gc.IsNil)

	var expected string
	if subcmd.Info().Args != "" {
		expected = "(?sm).*^Usage: juju backups " +
			regexp.QuoteMeta(subcmd.Info().Name) +
			` \[options\] ` + regexp.QuoteMeta(subcmd.Info().Args) + ".+"
	} else {
		expected = "(?sm).*^Usage: juju backups " +
			regexp.QuoteMeta(subcmd.Info().Name) +
			` \[options\].+`
	}
	c.Check(jujutesting.Stdout(ctx), gc.Matches, expected)

	expected = "(?sm).*^Summary:\n" + regexp.QuoteMeta(subcmd.Info().Purpose) + "$.*"
	c.Check(jujutesting.Stdout(ctx), gc.Matches, expected)

	expected = "(?sm).*^Details:" + regexp.QuoteMeta(subcmd.Info().Doc) + "$.*"
	c.Check(jujutesting.Stdout(ctx), gc.Matches, expected)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:22,代码来源:package_test.go

示例12: Register

func (m *mockRegister) Register(command cmd.Command) {
	m.commands = append(m.commands, command.Info().Name)
}
开发者ID:bac,项目名称:juju,代码行数:3,代码来源:commands_test.go


注:本文中的github.com/juju/cmd.Command类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。