本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例14: verifyFlags
func verifyFlags(opts *Options, fs *flag.FlagSet) {
if len(fs.Args()) == 0 && opts.showText == "" {
fs.Usage()
os.Exit(1)
}
}
示例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)
}