// Run runs the command to get free IP addresses.
13339
func (c *GetIPsCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	client := getClient(ctx)
	resp, err := client.ListFreeIPs(ctx, &c.req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printIPs(c.f.tsv, resp.Ips...)
	return 0
}
1266554
func run(dir, command string, args ...string) (string, error) {
	logger.Debugf("(%s) %s %v", dir, command, args)

	cmd := exec.Command(command, args...)
	if dir != "" {
		cmd.Dir = dir
	}

	out, err := cmd.CombinedOutput()
	output := string(out)

	logger.Debugf("output: %v", output)
	return output, err
}
690502
func (c *CmdSimpleFSWrite) Run() error {

	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	ctx := context.TODO()

	opid, err := cli.SimpleFSMakeOpid(ctx)
	if err != nil {
		return err
	}

	// if we're appending, we'll need the size
	if c.flags&keybase1.OpenFlags_APPEND != 0 {
		e, err := cli.SimpleFSStat(context.TODO(), keybase1.SimpleFSStatArg{Path: c.path})
		if err != nil {
			return err
		}
		c.offset = int64(e.Size)
	}

	err = cli.SimpleFSOpen(context.TODO(), keybase1.SimpleFSOpenArg{
		OpID:  opid,
		Dest:  c.path,
		Flags: c.flags,
	})
	if err != nil {
		return err
	}
	defer cli.SimpleFSClose(context.TODO(), opid)

	buf := make([]byte, 0, c.bufSize)
	r := bufio.NewReader(os.Stdin)

	for {
		n, err := r.Read(buf[:cap(buf)])
		buf = buf[:n]
		if n == 0 {
			if err == nil {
				continue
			}
			if err == io.EOF {
				break
			}
		}

		err2 := cli.SimpleFSWrite(context.TODO(), keybase1.SimpleFSWriteArg{
			OpID:    opid,
			Offset:  c.offset,
			Content: buf[:],
		})
		if err2 != nil {
			err = err2
			break
		}
		c.offset += int64(n)

		if err != nil {
			if err == io.EOF {
				err = nil
			}
			break
		}
	}
	c.G().Log.Debug("SimpleFS: return with error %v", err)
	return err
}
1329161
func (cmd *Command) Run(args ...string) error {
	fs := flag.NewFlagSet("buildtsi", flag.ExitOnError)
	dataDir := fs.String("datadir", "", "data directory")
	walDir := fs.String("waldir", "", "WAL directory")
	fs.IntVar(&cmd.concurrency, "concurrency", runtime.GOMAXPROCS(0), "Number of workers to dedicate to shard index building. Defaults to GOMAXPROCS")
	fs.StringVar(&cmd.databaseFilter, "database", "", "optional: database name")
	fs.StringVar(&cmd.retentionFilter, "retention", "", "optional: retention policy")
	fs.StringVar(&cmd.shardFilter, "shard", "", "optional: shard id")
	fs.Int64Var(&cmd.maxLogFileSize, "max-log-file-size", tsi1.DefaultMaxIndexLogFileSize, "optional: maximum log file size")
	fs.Uint64Var(&cmd.maxCacheSize, "max-cache-size", tsm1.DefaultCacheMaxMemorySize, "optional: maximum cache size")
	fs.IntVar(&cmd.batchSize, "batch-size", defaultBatchSize, "optional: set the size of the batches we write to the index. Setting this can have adverse affects on performance and heap requirements")
	fs.BoolVar(&cmd.Verbose, "v", false, "verbose")
	fs.SetOutput(cmd.Stdout)
	if err := fs.Parse(args); err != nil {
		return err
	} else if fs.NArg() > 0 || *dataDir == "" || *walDir == "" {
		fs.Usage()
		return nil
	}
	cmd.Logger = logger.New(cmd.Stderr)

	return cmd.run(*dataDir, *walDir)
}
239393
func (engine *Engine) Run(addr ...string) (err error) {
	defer func() { debugPrintError(err) }()

	address := resolveAddress(addr)
	debugPrint("Listening and serving HTTP on %s\n", address)
	err = http.ListenAndServe(address, engine)
	return
}
572579
func (c *disableCommand) Run(ctx *cmd.Context) error {
	api, err := c.apiFunc(c)
	if err != nil {
		return errors.Annotate(err, "cannot connect to the API")
	}
	defer api.Close()

	return api.SwitchBlockOn(c.target, c.message)
}
815198
func (mung *Mung) Run(addr string) {
	log.Fatal(http.ListenAndServe(addr, mung))
}
520209
func Run(c *client.Client, appID string, command string) (api.AppRunResponse, error) {
	req := api.AppRunRequest{Command: command}
	body, err := json.Marshal(req)

	if err != nil {
		return api.AppRunResponse{}, err
	}

	u := fmt.Sprintf("/v1/apps/%s/run", appID)

	resBody, err := c.BasicRequest("POST", u, body)

	if err != nil {
		return api.AppRunResponse{}, err
	}

	out := make([]interface{}, 2)

	if err = json.Unmarshal([]byte(resBody), &out); err != nil {
		return api.AppRunResponse{}, err
	}

	return api.AppRunResponse{Output: out[1].(string), ReturnCode: int(out[0].(float64))}, nil
}
725527
func (c *GetSwitchesCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	client := getClient(ctx)
	resp, err := client.ListSwitches(ctx, &c.req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printSwitches(c.f.tsv, resp.Switches...)
	return 0
}
448790
func (c *EditNICCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	// TODO(smut): Validate required fields client-side.
	req := &crimson.UpdateNICRequest{
		Nic: &c.nic,
		UpdateMask: getUpdateMask(&c.Flags, map[string]string{
			"mac":    "mac_address",
			"switch": "switch",
			"port":   "switchport",
		}),
	}
	client := getClient(ctx)
	resp, err := client.UpdateNIC(ctx, req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printNICs(c.f.tsv, resp)
	return 0
}
1028522
func (c *command) run() []byte {
	cmd := exec.Command(c.program, c.args...)
	var stdout, stderr bytes.Buffer
	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	err := cmd.Run()
	out := stdout.Bytes()
	if err != nil {
		log.Fatalf("Could not run %v: %v: %v: %v", c, err, string(out), stderr.String())
	}
	return out
}
455314
func (c *ListCommand) Run(ctx *cmd.Context) error {
	return errors.Trace(c.RunWithAPI(ctx, func(api SubnetAPI, ctx *cmd.Context) error {
		// Validate space and/or zone, if given to display a nicer error
		// message.
		// Get the list of subnets, filtering them as requested.
		subnets, err := api.ListSubnets(c.spaceTag, c.ZoneName)
		if err != nil {
			return errors.Annotate(err, "cannot list subnets")
		}

		// Display a nicer message in case no subnets were found.
		if len(subnets) == 0 {
			if c.SpaceName != "" || c.ZoneName != "" {
				ctx.Infof("No subnets found matching requested criteria.")
			} else {
				ctx.Infof("No subnets to display.")
			}
			return nil
		}

		// Construct the output list for displaying with the chosen
		// format.
		result := formattedList{
			Subnets: make(map[string]formattedSubnet),
		}
		for _, sub := range subnets {
			subResult := formattedSubnet{
				ProviderId:        sub.ProviderId,
				ProviderNetworkId: sub.ProviderNetworkId,
				Zones:             sub.Zones,
			}

			// Use the CIDR to determine the subnet type.
			if ip, _, err := net.ParseCIDR(sub.CIDR); err != nil {
				return errors.Errorf("subnet %q has invalid CIDR", sub.CIDR)
			} else if ip.To4() != nil {
				subResult.Type = typeIPv4
			} else if ip.To16() != nil {
				subResult.Type = typeIPv6
			}
			if sub.SpaceTag != "" {
				// Space must be valid, but verify anyway.
				spaceTag, err := names.ParseSpaceTag(sub.SpaceTag)
				if err != nil {
					return errors.Annotatef(err, "subnet %q has invalid space", sub.CIDR)
				}
				subResult.Space = spaceTag.Id()
			}

			// Display correct status according to the life cycle value.
			switch sub.Life {
			case params.Alive:
				subResult.Status = statusInUse
			case params.Dying, params.Dead:
				subResult.Status = statusTerminating
			}

			result.Subnets[sub.CIDR] = subResult
		}

		return c.Out.Write(ctx, result)
	}))
}
196784
func (c *CmdSimpleFSRemove) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	ctx := context.TODO()

	paths, err := doSimpleFSGlob(ctx, c.G(), cli, c.paths)
	if err != nil {
		return err
	}

	for _, path := range paths {
		opid, err2 := cli.SimpleFSMakeOpid(ctx)
		if err2 != nil {
			return err2
		}
		defer cli.SimpleFSClose(ctx, opid)
		c.G().Log.Debug("SimpleFSRemove %s", path.Kbfs())
		err = cli.SimpleFSRemove(ctx, keybase1.SimpleFSRemoveArg{
			OpID:      opid,
			Path:      path,
			Recursive: c.recurse,
		})
		if err != nil {
			break
		}
		err = cli.SimpleFSWait(ctx, opid)
		if err != nil {
			break
		}
	}
	return err
}
1085065
func (c *dumpCommand) Run(ctx *cmd.Context) error {
	client, err := c.getAPI()
	if err != nil {
		return err
	}
	defer client.Close()

	_, modelDetails, err := c.ModelCommandBase.ModelDetails()
	if err != nil {
		return errors.Annotate(err, "getting model details")
	}

	modelTag := names.NewModelTag(modelDetails.ModelUUID)
	results, err := client.DumpModel(modelTag, c.simplified)
	if err != nil {
		return err
	}

	return c.out.Write(ctx, results)
}
982998
func (c *RFCListCommand) Run(args []string) int {
	if len(args) != 0 {
		c.Ui.Error(c.Help())
		return 1
	}

	c.InitOpts()
	_, err := c.parseOpts(args)
	if err != nil {
		if errwrap.Contains(err, "flag: help requested") {
			return 0
		}
		return 1
	}

	var rfcs rfcNums
	sockaddr.VisitAllRFCs(func(rfcNum uint, sas sockaddr.SockAddrs) {
		rfcs = append(rfcs, rfcNum)
	})

	sort.Sort(rfcs)

	for _, rfcNum := range rfcs {
		c.Ui.Output(fmt.Sprintf("%d", rfcNum))
	}

	return 0
}
706202
func (c *GetRacksCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	client := getClient(ctx)
	resp, err := client.ListRacks(ctx, &c.req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printRacks(c.f.tsv, resp.Racks...)
	return 0
}
1024988
func (t *Tango) Run(args ...interface{}) {
	addr := getAddress(args...)
	t.logger.Info("Listening on http://" + addr)

	t.Server.Addr = addr
	t.Server.Handler = t

	err := t.ListenAndServe()
	if err != nil {
		t.logger.Error(err)
	}
}