// Run sets up the output directory.
487297
func (s *StepOutputDir) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
	ui := state.Get("ui").(packer.Ui)

	if _, err := os.Stat(s.Path); err == nil && s.Force {
		ui.Say("Deleting previous output directory...")
		os.RemoveAll(s.Path)
	}

	// Create the directory
	if err := os.MkdirAll(s.Path, 0755); err != nil {
		state.Put("error", err)
		return multistep.ActionHalt
	}

	// Make sure we can write in the directory
	f, err := os.Create(filepath.Join(s.Path, "_packer_perm_check"))
	if err != nil {
		err = fmt.Errorf("Couldn't write to output directory: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}
	f.Close()
	os.Remove(f.Name())

	s.success = true
	return multistep.ActionContinue
}
461003
func (cmd *GenerateConfigCommand) Run(_ context.Context) error {
	conf := server.NewConfig()
	ret, err := toml.Marshal(*conf)
	if err != nil {
		return errors.Wrap(err, "unmarshalling default config")
	}
	fmt.Fprintf(cmd.Stdout, "%s\n", ret)
	return nil
}
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
}
543904
func (c *listImagesCommand) Run(ctx *cmd.Context) (err error) {
	api, err := getImageMetadataListAPI(c)
	if err != nil {
		return err
	}
	defer api.Close()

	found, err := api.List(c.Stream, c.Region, c.Series, c.Arches, c.VirtType, c.RootStorageType)
	if err != nil {
		return err
	}
	if len(found) == 0 {
		return nil
	}

	info, errs := convertDetailsToInfo(found)
	if len(errs) > 0 {
		// display individual error
		fmt.Fprintf(ctx.Stderr, strings.Join(errs, "\n"))
	}

	var output interface{}
	switch c.out.Name() {
	case "yaml", "json":
		output = groupMetadata(info)
	default:
		{
			sort.Sort(metadataInfos(info))
			output = info
		}
	}
	return c.out.Write(ctx, output)
}
637376
func (f RemoteFile) Run(rootPath string, data Data) error {
	return chdir(rootPath, func() error {
		if f.Should != nil && !f.Should(data) {
			return nil
		}

		res, err := http.Get(f.RemotePath)
		if err != nil {
			return errors.WithStack(err)
		}
		code := res.StatusCode
		if code < 200 || code >= 300 {
			return errors.WithStack(fmt.Errorf("Error fetching %s (%d)", f.RemotePath, code))
		}

		bb := bytes.Buffer{}
		_, err = io.Copy(&bb, res.Body)
		if err != nil {
			return errors.WithStack(err)
		}
		return f.save(rootPath, f.Path, bb.String())
	})
}
523606
func (cli *Cli) Run(args []string) error {
	if err := cli.doInit(); err != nil {
		panic(err)
	}
	inFlow := &flow.Step{Desc: "RootIn", Exiter: exiter}
	outFlow := &flow.Step{Desc: "RootOut", Exiter: exiter}
	return cli.parse(args[1:], inFlow, inFlow, outFlow)
}
93309
func (m *Main) Run() error {
	src, err := NewSource(
		OptSrcPath(m.Path),
		OptSrcSubjectAt(m.SubjectAt),
	)
	if err != nil {
		return errors.Wrap(err, "getting file source")
	}

	translateColumns := true
	parser := pdk.NewDefaultGenericParser()
	if len(m.SubjectPath) == 0 && m.SubjectAt == "" {
		parser.Subjecter = pdk.BlankSubjecter{}
		translateColumns = false
	} else if len(m.SubjectPath) == 0 && m.SubjectAt != "" {
		m.SubjectPath = []string{m.SubjectAt}
		parser.EntitySubjecter = pdk.SubjectPath(m.SubjectPath)
	} else {
		parser.EntitySubjecter = pdk.SubjectPath(m.SubjectPath)
	}

	mapper := pdk.NewCollapsingMapper()
	mapper.Framer = &m.Framer
	if translateColumns {
		mapper.ColTranslator = pdk.NewMapFieldTranslator()
	}

	indexer, err := pdk.SetupPilosa(m.PilosaHosts, m.Index, nil, m.BatchSize)
	if err != nil {
		return errors.Wrap(err, "setting up Pilosa")
	}
	ingester := pdk.NewIngester(src, parser, mapper, indexer)

	go func() {
		err = pdk.StartMappingProxy(m.Proxy, pdk.NewPilosaForwarder(m.PilosaHosts[0], mapper.Translator, mapper.ColTranslator))
		log.Fatal(errors.Wrap(err, "starting mapping proxy"))
	}()
	return errors.Wrap(ingester.Run(), "running ingester")
}
1115408
func Run(command string, args ...string) error {
	cmd := exec.Command(command, args...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	return RunCommand(cmd, false)
}
1079728
func (c *CmdGitMdget) Run() error {
	cli, err := GetGitClient(c.G())
	ctx := context.Background()
	if err != nil {
		return err
	}

	var res []keybase1.GitRepoResult
	if len(c.folder) > 0 {
		folder, err := ParseTLF(c.folder)
		if err != nil {
			return err
		}
		res, err = cli.GetGitMetadata(ctx, folder)
		if err != nil {
			return err
		}
	} else {
		res, err = cli.GetAllGitMetadata(ctx)
		if err != nil {
			return err
		}
	}

	jsonStr, err := json.MarshalIndent(res, "", "    ")
	if err != nil {
		return err
	}

	fmt.Println(string(jsonStr))
	return nil
}
678529
func (c *CmdSimpleFSSyncDisable) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	ctx := context.TODO()
	arg := keybase1.SimpleFSSetFolderSyncConfigArg{
		Config: keybase1.FolderSyncConfig{
			Mode: keybase1.FolderSyncMode_DISABLED,
		},
		Path: c.path,
	}

	subpath := pathMinusTlf(c.path)
	if subpath != "" {
		arg.Path, err = toTlfPath(c.path)
		if err != nil {
			return err
		}
		res, err := cli.SimpleFSFolderSyncConfigAndStatus(ctx, arg.Path)
		if err != nil {
			return err
		}

		if res.Config.Mode == keybase1.FolderSyncMode_DISABLED {
			return fmt.Errorf("No syncing enabled on %s", arg.Path)
		} else if res.Config.Mode == keybase1.FolderSyncMode_ENABLED {
			return fmt.Errorf(
				"Cannot disable single path on fully-synced TLF %s", arg.Path)
		}

		found := false
		parentFound := ""
		for _, p := range res.Config.Paths {
			if p == subpath {
				found = true
			} else {
				toCheck := p
				if !strings.HasSuffix(p, "/") {
					toCheck = p + "/"
				}
				if strings.HasPrefix(subpath, toCheck) {
					parentFound = p
				}
				arg.Config.Paths = append(arg.Config.Paths, p)
			}
		}

		if parentFound != "" {
			ui := c.G().UI.GetTerminalUI()
			ui.Printf("%s will remain synced because its parent path (%s) "+
				"is still synced\n", subpath, parentFound)
		}

		if !found {
			return nil
		}

		arg.Config.Mode = keybase1.FolderSyncMode_PARTIAL
	}

	return cli.SimpleFSSetFolderSyncConfig(ctx, arg)
}
432593
func (m *Main) Run() error {
	src, err := NewJSONSource(WithAddr(m.Bind))
	if err != nil {
		return errors.Wrap(err, "getting json source")
	}

	if m.TranslatorDir == "" {
		m.TranslatorDir, err = ioutil.TempDir("", "pdk")
		if err != nil {
			return errors.Wrap(err, "creating temp directory")
		}
	}

	log.Println("listening on", src.Addr())

	translateColumns := true
	parser := pdk.NewDefaultGenericParser()
	if len(m.SubjectPath) == 0 {
		parser.Subjecter = pdk.BlankSubjecter{}
		translateColumns = false
	} else {
		parser.EntitySubjecter = pdk.SubjectPath(m.SubjectPath)
	}

	mapper := pdk.NewCollapsingMapper()
	mapper.Translator, err = leveldb.NewTranslator(m.TranslatorDir)
	if err != nil {
		return errors.Wrap(err, "creating translator")
	}
	mapper.Framer = &m.Framer
	if translateColumns {
		log.Println("translating columns")
		mapper.ColTranslator, err = leveldb.NewFieldTranslator(m.TranslatorDir, "__columns")
		if err != nil {
			return errors.Wrap(err, "creating column translator")
		}
	} else {
		log.Println("not translating columns")
	}

	indexer, err := pdk.SetupPilosa(m.PilosaHosts, m.Index, nil, m.BatchSize)
	if err != nil {
		return errors.Wrap(err, "setting up Pilosa")
	}

	ingester := pdk.NewIngester(src, parser, mapper, indexer)
	if len(m.AllowedFields) > 0 {
		ingester.AllowedFields = make(map[string]bool)
		for _, fram := range m.AllowedFields {
			ingester.AllowedFields[fram] = true
		}
	}
	m.proxy = http.Server{
		Addr:    m.Proxy,
		Handler: pdk.NewPilosaForwarder(m.PilosaHosts[0], mapper.Translator, mapper.ColTranslator),
	}
	go func() {
		err := m.proxy.ListenAndServe()
		if err != nil {
			log.Printf("proxy closed: %v", err)
		}
	}()
	return errors.Wrap(ingester.Run(), "running ingester")
}
1100748
func (c GetCmd) Run(ctx *cmd.Context) error {
	hookContext, ok := c.compContext.(downloader)
	if !ok {
		return errors.Errorf("invalid component context")
	}
	filePath, err := hookContext.Download(c.resourceName)
	if err != nil {
		return errors.Annotate(err, "could not download resource")
	}

	if _, err := fmt.Fprintf(ctx.Stdout, filePath); err != nil {
		return errors.Annotate(err, "could not write resource path to stdout")
	}
	return nil
}
972166
func (c *diffCommand) Run(ctx *cmd.Context) error {
	client, err := c.getAPI()
	if err != nil {
		return err
	}
	defer func() { _ = client.Close() }()

	// Partially apply our time format
	formatTime := func(t time.Time) string {
		return common.FormatTime(&t, c.isoTime)
	}

	deltas, err := client.BranchInfo(c.branchName, c.detailed, formatTime)
	if err != nil {
		return errors.Trace(err)
	}
	return errors.Trace(c.out.Write(ctx, deltas))
}
676319
func (c *AddDRACCmd) 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.CreateDRACRequest{
		Drac: &c.drac,
	}
	client := getClient(ctx)
	resp, err := client.CreateDRAC(ctx, req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printDRACs(c.f.tsv, resp)
	return 0
}
780593
func (c *CmdSimpleFSSyncShow) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	ctx := context.TODO()
	ui := c.G().UI.GetTerminalUI()
	if c.getAll {
		res, err := cli.SimpleFSSyncConfigAndStatus(ctx)
		if err != nil {
			return err
		}

		for _, folder := range res.Folders {
			p, err := makeSimpleFSPath(mountDir + "/" + folder.Folder.String())
			if err != nil {
				return err
			}
			ui.Printf("%s\n", folder.Folder)
			err = printFolderStatus(
				ctx, cli, ui, folder.Config, folder.Status, "  ", p, false)
			if err != nil {
				return err
			}
			ui.Printf("\n")
		}

		printPrefetchStatus(
			ui, res.OverallStatus.PrefetchStatus,
			res.OverallStatus.PrefetchProgress,
			res.OverallStatus.StoredBytesTotal, "")
		printLocalStats(ui, res.OverallStatus)
	} else {
		res, err := cli.SimpleFSFolderSyncConfigAndStatus(ctx, c.path)
		if err != nil {
			return err
		}
		tlfPath, err := toTlfPath(c.path)
		if err != nil {
			return err
		}
		return printFolderStatus(
			ctx, cli, ui, res.Config, res.Status, "", tlfPath, true)
	}

	return nil
}
238632
func (c *CmdSimpleFSQuota) Run() error {
	cli, err := GetSimpleFSClient(c.G())
	if err != nil {
		return err
	}

	var usage keybase1.SimpleFSQuotaUsage
	if c.teamName.Depth() == 0 {
		usage, err = cli.SimpleFSGetUserQuotaUsage(context.TODO())
	} else {
		usage, err = cli.SimpleFSGetTeamQuotaUsage(context.TODO(), c.teamName)
	}
	if err != nil {
		return err
	}

	return c.output(usage)
}
1242068
func (o *DiffOptions) Run() error {
	differ, err := NewDiffer("LIVE", "MERGED")
	if err != nil {
		return err
	}
	defer differ.TearDown()

	printer := Printer{}

	r := o.Builder.
		Unstructured().
		NamespaceParam(o.CmdNamespace).DefaultNamespace().
		FilenameParam(o.EnforceNamespace, &o.FilenameOptions).
		Flatten().
		Do()
	if err := r.Err(); err != nil {
		return err
	}

	err = r.Visit(func(info *resource.Info, err error) error {
		if err != nil {
			return err
		}

		if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil {
			return err
		}

		local := info.Object.DeepCopyObject()
		for i := 1; i <= maxRetries; i++ {
			if err = info.Get(); err != nil {
				if !errors.IsNotFound(err) {
					return err
				}
				info.Object = nil
			}

			force := i == maxRetries
			if force {
				klog.Warningf(
					"Object (%v: %v) keeps changing, diffing without lock",
					info.Object.GetObjectKind().GroupVersionKind(),
					info.Name,
				)
			}
			obj := InfoObject{
				LocalObj:        local,
				Info:            info,
				Encoder:         scheme.DefaultJSONEncoder(),
				OpenAPI:         o.OpenAPISchema,
				Force:           force,
				ServerSideApply: o.ServerSideApply,
				ForceConflicts:  o.ForceConflicts,
			}

			err = differ.Diff(obj, printer)
			if !isConflict(err) {
				break
			}
		}
		return err
	})
	if err != nil {
		return err
	}

	return differ.Run(o.Diff)
}