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


Golang FlagSet.Args方法代码示例

本文整理汇总了Golang中flag.FlagSet.Args方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.Args方法的具体用法?Golang FlagSet.Args怎么用?Golang FlagSet.Args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flag.FlagSet的用法示例。


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

示例1: Run

func (cmd *esxcli) Run(f *flag.FlagSet) error {
	c, err := cmd.Client()
	if err != nil {
		return nil
	}

	host, err := cmd.HostSystem()
	if err != nil {
		return err
	}

	e, err := NewExecutor(c, host)
	if err != nil {
		return err
	}

	res, err := e.Run(f.Args())
	if err != nil {
		return err
	}

	if len(res.Values) == 0 {
		return nil
	}

	// TODO: OutputFlag / format options
	switch res.Info.Hints.Formatter() {
	case "table":
		cmd.formatTable(res)
	default:
		cmd.formatSimple(res)
	}

	return nil
}
开发者ID:Tiger66639,项目名称:jupiter-brain,代码行数:35,代码来源:esxcli.go

示例2: Run

func (cmd *destroy) Run(f *flag.FlagSet) error {
	vms, err := cmd.VirtualMachines(f.Args())
	if err != nil {
		return err
	}

	for _, vm := range vms {
		task, err := vm.PowerOff(context.TODO())
		if err != nil {
			return err
		}

		// Ignore error since the VM may already been in powered off state.
		// vm.Destroy will fail if the VM is still powered on.
		_ = task.Wait(context.TODO())

		task, err = vm.Destroy(context.TODO())
		if err != nil {
			return err
		}

		err = task.Wait(context.TODO())
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:29,代码来源:destroy.go

示例3: Run

func (cmd *change) Run(f *flag.FlagSet) error {
	ctx := context.TODO()

	finder, err := cmd.Finder()
	if err != nil {
		return err
	}

	for _, path := range f.Args() {
		clusters, err := finder.ClusterComputeResourceList(ctx, path)
		if err != nil {
			return err
		}

		for _, cluster := range clusters {
			task, err := cluster.Reconfigure(ctx, &cmd.ClusterConfigSpecEx, true)
			if err != nil {
				return err
			}

			_, err = task.WaitForResult(ctx, nil)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:kristinn,项目名称:govmomi,代码行数:29,代码来源:change.go

示例4: Prepare

func (cmd *ovfx) Prepare(f *flag.FlagSet) (string, error) {
	var err error

	args := f.Args()
	if len(args) != 1 {
		return "", errors.New("no file specified")
	}

	cmd.Client, err = cmd.DatastoreFlag.Client()
	if err != nil {
		return "", err
	}

	cmd.Datacenter, err = cmd.DatastoreFlag.Datacenter()
	if err != nil {
		return "", err
	}

	cmd.Datastore, err = cmd.DatastoreFlag.Datastore()
	if err != nil {
		return "", err
	}

	cmd.ResourcePool, err = cmd.ResourcePoolFlag.ResourcePool()
	if err != nil {
		return "", err
	}

	return f.Arg(0), nil
}
开发者ID:tjyang,项目名称:govmomi,代码行数:30,代码来源:ovf.go

示例5: Run

func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
	if len(f.Args()) < 1 {
		return flag.ErrHelp
	}
	datacentersToDestroy := f.Args()

	client, err := cmd.ClientFlag.Client()
	if err != nil {
		return err
	}

	finder := find.NewFinder(client, false)
	for _, datacenterToDestroy := range datacentersToDestroy {
		foundDatacenters, err := finder.DatacenterList(context.TODO(), datacenterToDestroy)
		if err != nil {
			return err
		}
		for _, foundDatacenter := range foundDatacenters {
			task, err := foundDatacenter.Destroy(context.TODO())
			if err != nil {
				return err
			}

			if err := task.Wait(context.TODO()); err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:robvanmieghem,项目名称:machine,代码行数:30,代码来源:destroy.go

示例6: Run

func (cmd *set) Run(ctx context.Context, f *flag.FlagSet) error {
	c, err := cmd.Client()
	if err != nil {
		return err
	}

	refs, err := cmd.ManagedObjects(ctx, f.Args())
	if err != nil {
		return err
	}

	m := object.NewAuthorizationManager(c)
	rl, err := m.RoleList(ctx)
	if err != nil {
		return err
	}

	role := rl.ByName(cmd.role)
	if role == nil {
		return fmt.Errorf("role '%s' not found", cmd.role)
	}
	cmd.Permission.RoleId = role.RoleId

	perms := []types.Permission{cmd.Permission}

	for _, ref := range refs {
		err = m.SetEntityPermissions(ctx, ref, perms)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:robvanmieghem,项目名称:machine,代码行数:34,代码来源:set.go

示例7: Run

func (cmd *disconnect) Run(ctx context.Context, f *flag.FlagSet) error {
	vm, err := cmd.VirtualMachine()
	if err != nil {
		return err
	}

	if vm == nil {
		return flag.ErrHelp
	}

	devices, err := vm.Device(context.TODO())
	if err != nil {
		return err
	}

	for _, name := range f.Args() {
		device := devices.Find(name)
		if device == nil {
			return fmt.Errorf("device '%s' not found", name)
		}

		if err = devices.Disconnect(device); err != nil {
			return err
		}

		if err = vm.EditDevice(context.TODO(), device); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:robvanmieghem,项目名称:machine,代码行数:32,代码来源:disconnect.go

示例8: Run

func (cmd *ls) Run(f *flag.FlagSet) error {
	finder, err := cmd.Finder()
	if err != nil {
		return err
	}

	lr := listResult{
		Elements: nil,
		Long:     cmd.Long,
	}

	args := f.Args()
	if len(args) == 0 {
		args = []string{"."}
	}

	for _, arg := range args {
		es, err := finder.ManagedObjectListChildren(context.TODO(), arg)
		if err != nil {
			return err
		}

		lr.Elements = append(lr.Elements, es...)
	}

	return cmd.WriteResult(lr)
}
开发者ID:yxdh,项目名称:govmomi,代码行数:27,代码来源:command.go

示例9: Run

func (cmd *create) Run(f *flag.FlagSet) error {
	if f.NArg() == 0 {
		return flag.ErrHelp
	}

	finder, err := cmd.Finder()
	if err != nil {
		return err
	}

	for _, arg := range f.Args() {
		dir := path.Dir(arg)
		base := path.Base(arg)
		parents, err := finder.ResourcePoolList(context.TODO(), dir)
		if err != nil {
			if _, ok := err.(*find.NotFoundError); ok {
				return fmt.Errorf("cannot create resource pool '%s': parent not found", base)
			}
			return err
		}

		for _, parent := range parents {
			_, err = parent.Create(context.TODO(), base, cmd.ResourceConfigSpec)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:kristinn,项目名称:govmomi,代码行数:31,代码来源:create.go

示例10: Run

func (cmd *mv) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() < 2 {
		return flag.ErrHelp
	}

	finder, err := cmd.Finder()
	if err != nil {
		return err
	}

	n := f.NArg() - 1

	folder, err := finder.Folder(ctx, f.Arg(n))
	if err != nil {
		return err
	}

	objs, err := cmd.ManagedObjects(ctx, f.Args()[:n])
	if err != nil {
		return err
	}

	task, err := folder.MoveInto(ctx, objs)
	if err != nil {
		return err
	}

	logger := cmd.ProgressLogger(fmt.Sprintf("moving %d objects to %s... ", len(objs), folder.InventoryPath))
	_, err = task.WaitForResult(ctx, logger)
	logger.Wait()

	return err
}
开发者ID:vmware,项目名称:vic,代码行数:33,代码来源:mv.go

示例11: Run

func (cmd *execCmd) Run(fs *flag.FlagSet) {
	cmd.InitClient(false)
	cmd.exitStatus = 0

	cmd.ValidateFlags()

	args := fs.Args()
	if len(args) < 1 {
		fmt.Println("no command to exec")
		os.Exit(1)
		return
	}
	var c *exec.Cmd
	if len(args) > 2 {
		c = exec.Command(args[0], args[1:]...)
	} else {
		c = exec.Command(args[0])
	}
	attachCmd(c)
	err := c.Start()
	if err != nil {
		panic(err)
	}

	cmd.RegisterWithExitHook(map[string]string(*cmd.services), false)

	exitCh := exitStatusCh(c)
	cmd.exitStatus = int(<-exitCh)
	close(cmd.exitSignalCh)
	time.Sleep(time.Second)
}
开发者ID:ericcapricorn,项目名称:flynn,代码行数:31,代码来源:exec.go

示例12: Run

func (cmd *download) Run(ctx context.Context, f *flag.FlagSet) error {
	args := f.Args()
	if len(args) != 2 {
		return errors.New("invalid arguments")
	}

	ds, err := cmd.Datastore()
	if err != nil {
		return err
	}

	p := soap.DefaultDownload

	src := args[0]
	dst := args[1]

	if dst == "-" {
		f, _, err := ds.Download(ctx, src, &p)
		if err != nil {
			return err
		}
		_, err = io.Copy(os.Stdout, f)
		return err
	}

	if cmd.OutputFlag.TTY {
		logger := cmd.ProgressLogger("Downloading... ")
		p.Progress = logger
		defer logger.Wait()
	}

	return ds.DownloadFile(ctx, src, dst, &p)
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:33,代码来源:download.go

示例13: Run

func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() == 0 {
		return flag.ErrHelp
	}

	finder, err := cmd.Finder()
	if err != nil {
		return err
	}

	for _, arg := range f.Args() {
		folders, err := finder.FolderList(ctx, arg)
		if err != nil {
			return err
		}

		for _, folder := range folders {
			task, err := folder.Destroy(ctx)
			if err != nil {
				return err
			}

			err = task.Wait(ctx)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:frapposelli,项目名称:govmomi,代码行数:31,代码来源:destroy.go

示例14: verifyFlags

func verifyFlags(opts *Options, fs *flag.FlagSet) {

	if len(fs.Args()) == 0 && opts.showText == "" {
		fs.Usage()
		os.Exit(1)
	}
}
开发者ID:suapapa,项目名称:subtitle-raider,代码行数:7,代码来源:flag.go

示例15: Run

func (cmd *ls) Run(f *flag.FlagSet) error {
	ds, err := cmd.Datastore()
	if err != nil {
		return err
	}

	b, err := ds.Browser(context.TODO())
	if err != nil {
		return err
	}

	args := f.Args()
	if len(args) == 0 {
		args = []string{""}
	}

	result := &listOutput{
		rs:   make([]types.HostDatastoreBrowserSearchResults, 0),
		long: cmd.long,
	}

	for _, arg := range args {
		spec := types.HostDatastoreBrowserSearchSpec{
			MatchPattern: []string{"*"},
		}

		if cmd.long {
			spec.Details = &types.FileQueryFlags{
				FileType:     true,
				FileSize:     true,
				FileOwner:    types.NewBool(true), // TODO: omitempty is generated, but seems to be required
				Modification: true,
			}
		}

		for i := 0; ; i++ {
			r, err := cmd.ListPath(b, arg, spec)
			if err != nil {
				// Treat the argument as a match pattern if not found as directory
				if i == 0 && types.IsFileNotFound(err) {
					spec.MatchPattern[0] = path.Base(arg)
					arg = path.Dir(arg)
					continue
				}

				return err
			}

			// Treat an empty result against match pattern as file not found
			if i == 1 && len(r.File) == 0 {
				return fmt.Errorf("File %s/%s was not found", r.FolderPath, spec.MatchPattern[0])
			}

			result.add(r)
			break
		}
	}

	return cmd.WriteResult(result)
}
开发者ID:EricYT,项目名称:govmomi,代码行数:60,代码来源:ls.go


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