Repository: dolthub/dolt
File: go/cmd/dolt/commands/ci/view.go (Go)

Code before:
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(fmt.Errorf("dolt ci has not been initialized, please initialize with: dolt ci init")), usage)
	}

	name, email, err := env.GetNameAndEmail(cliCtx.Config())
	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}
	wm := dolt_ci.NewWorkflowManager(name, email, queryist.Query)

	config, err := wm.GetWorkflowConfig(sqlCtx, workflowName)
	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}

	savedQueries, err := getSavedQueries(sqlCtx, queryist)
	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}

	var toPrint interface{}
	jobVal, ok := apr.GetValue(cli.JobFlag)
	if ok {
		toPrint, err = updateConfigQueryStatements(config, savedQueries, jobVal)
	} else {
		toPrint, err = updateConfigQueryStatements(config, savedQueries, "")
	}

	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}

	err = printWorkflowConfig(toPrint)

	return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

func printWorkflowConfig(toPrint interface{}) error {
	b, err := yaml.Marshal(toPrint)
	if err != nil {
		return err
	}

	cli.Println(string(b))
	return nil
}

func updateConfigQueryStatements(config *dolt_ci.WorkflowConfig, savedQueries map[string]string, jobName string) (interface{}, error) {
	for i, job := range config.Jobs {
		for j, _ := range job.Steps {
			step := job.Steps[j]
			if name := savedQueries[step.SavedQueryName.Value]; name != "" {

Review comment (suggestion):
I think I could just condense these into one line:
`toPrint, err = updateConfigQueryStatements(config, savedQueries, jobVal)`
`jobVal` will be nil if the arg isn't passed in

Code after:

	if !hasTables {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(fmt.Errorf("dolt ci has not been initialized, please initialize with: dolt ci init")), usage)
	}

	name, email, err := env.GetNameAndEmail(cliCtx.Config())
	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}
	wm := dolt_ci.NewWorkflowManager(name, email, queryist.Query)

	config, err := wm.GetWorkflowConfig(sqlCtx, workflowName)
	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}

	savedQueries, err := getSavedQueries(sqlCtx, queryist)
	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}

	// Check if --job was used. A jobVal of "" will be used if the flag was not set, and toPrint will get the full workflow.
	jobVal, _ := apr.GetValue(cli.JobFlag)
	toPrint, err := updateConfigQueryStatements(config, savedQueries, jobVal)

	if err != nil {
		return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
	}

	err = printWorkflowConfig(toPrint)

	return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

func printWorkflowConfig(toPrint interface{}) error {
	b, err := yaml.Marshal(toPrint)
	if err != nil {
		return err
	}

	cli.Println(string(b))
	return nil
}

func updateConfigQueryStatements(config *dolt_ci.WorkflowConfig, savedQueries map[string]string, jobName string) (interface{}, error) {
	for i, job := range config.Jobs {
		for j := range job.Steps {
			step := job.Steps[j]
			if name := savedQueries[step.SavedQueryName.Value]; name != "" {
				config.Jobs[i].Steps[j].SavedQueryStatement = yaml.Node{
					Kind:  yaml.ScalarNode,