Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {

RootCmd.AddCommand(config.ConfigCmd)

RootCmd.PersistentFlags().Bool("verbose", false, "show more verbose output")
RootCmd.PersistentFlags().BoolP("verbose", "v", false, "show more verbose output")
err := viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
if err != nil {
fmt.Printf("Error setting up: %s\n", err)
Expand Down Expand Up @@ -71,6 +71,18 @@ func Execute() {
}
}

var forgeTheme = &scribe.Theme{
Describe: func(s string) string {
return "\033[1;36m" + s + "\033[0m"
},
Print: func(s string) string {
return "\033[2m" + s + "\033[0m"
},
Error: func(err error) string {
return "\033[1;31m" + err.Error() + "\033[0m"
},
}

func rootFunc(cmd *cobra.Command, args []string) error {
verbose := viper.GetBool("verbose")

Expand All @@ -79,7 +91,7 @@ func rootFunc(cmd *cobra.Command, args []string) error {
writer = os.Stdout
}

scrb, err := scribe.NewScribe(writer, scribe.DefaultTheme)
scrb, err := scribe.NewScribe(writer, forgeTheme)
if err != nil {
return fmt.Errorf("setting up output: %w", err)
}
Expand All @@ -97,12 +109,14 @@ func rootFunc(cmd *cobra.Command, args []string) error {
}

for _, s := range args {
err := conf.Steps[s].Execute(conf.Steps, conf.Envs, conf.Vars, scrb)
err := conf.Steps[s].Execute(s, conf.Steps, conf.Envs, conf.Vars, scrb)
if err != nil {
return fmt.Errorf("executing step %v: %w", s, err)
}
}

fmt.Fprintln(writer)

return nil
}

Expand Down
20 changes: 15 additions & 5 deletions confile/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,49 @@ type Step struct {

// Execute runs the command that is specified for the step. It returns the output
// of the command and any errors it encounters.
func (s *Step) Execute(allSteps map[string]*Step, projectEnvs map[string]string, vars *vars.Vars, scrb scribe.Scriber) error {
func (s *Step) Execute(name string, allSteps map[string]*Step, projectEnvs map[string]string, vars *vars.Vars, scrb scribe.Scriber) error {
skipPre := viper.GetBool("solo") || viper.GetBool("no-pre")
skipPost := viper.GetBool("solo") || viper.GetBool("no-post")

s.projectEnvs = projectEnvs
s.vars = vars

if len(s.Pre) > 0 && !skipPre {
scrb.BeginDescribe(name + ": pre")
err := s.executeSteps(s.Pre, allSteps, scrb)
scrb.EndDescribe()
if err != nil {
return fmt.Errorf("step: execute pre: %w", err)
}
}

if len(s.Steps) > 0 {
scrb.BeginDescribe(name)
err := s.executeSteps(s.Steps, allSteps, scrb)
scrb.EndDescribe()
if err != nil {
return fmt.Errorf("step: execute steps: %w", err)
}
} else if len(s.Cmds) > 0 {
scrb.BeginDescribe(name)
err := s.executeCmds(scrb)
scrb.EndDescribe()
if err != nil {
return fmt.Errorf("step: execute cmds: %w", err)
}
} else {
scrb.BeginDescribe(name)
err := s.executeCmd(scrb)
scrb.EndDescribe()
if err != nil {
return fmt.Errorf("step: execute cmd: %w", err)
}
}

if len(s.Post) > 0 && !skipPost {
scrb.BeginDescribe(name + ": post")
err := s.executeSteps(s.Post, allSteps, scrb)
scrb.EndDescribe()
if err != nil {
return fmt.Errorf("step: execute post: %w", err)
}
Expand Down Expand Up @@ -86,13 +96,13 @@ func (s *Step) executeCmds(scrb scribe.Scriber) error {
}

func (s *Step) executeSteps(execList []string, allSteps map[string]*Step, scrb scribe.Scriber) error {
for _, step := range execList {
s, ok := allSteps[step]
for _, stepName := range execList {
step, ok := allSteps[stepName]
if !ok {
return fmt.Errorf("step does not exist: %v", step)
return fmt.Errorf("step does not exist: %v", stepName)
}

err := s.Execute(allSteps, s.projectEnvs, s.vars, scrb)
err := step.Execute(stepName, allSteps, step.projectEnvs, step.vars, scrb)
if err != nil {
return err
}
Expand Down
Loading