Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compute/init): post_init to support env_vars #1014

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
46 changes: 41 additions & 5 deletions pkg/commands/compute/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,21 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
}
}

err = spinner.Start()
if err != nil {
return err
if c.Globals.Flags.Verbose && len(md.File.Scripts.EnvVars) > 0 {
text.Description(out, "Environment variables set", strings.Join(md.File.Scripts.EnvVars, " "))
}

// If we're in verbose mode, the command output is shown.
// So in that case we don't want to have a spinner as it'll interweave output.
// In non-verbose mode we have a spinner running while the command execution is happening.
msg := "Running [scripts.post_init]..."
spinner.Message(msg)
if !c.Globals.Flags.Verbose {
err = spinner.Start()
if err != nil {
return err
}
spinner.Message(msg)
}

s := Shell{}
command, args := s.Build(postInit)
Expand All @@ -263,7 +272,7 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
err := fstexec.Command(fstexec.CommandOpts{
Args: args,
Command: command,
Env: c.manifest.File.Scripts.EnvVars,
Env: md.File.Scripts.EnvVars,
ErrLog: c.Globals.ErrLog,
Output: out,
Spinner: spinner,
Expand All @@ -272,9 +281,36 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
Verbose: c.Globals.Flags.Verbose,
})
if err != nil {
// In verbose mode we'll have the failure status AFTER the error output.
// But we can't just call StopFailMessage() without first starting the spinner.
if c.Globals.Flags.Verbose {
text.Break(out)
err := spinner.Start()
if err != nil {
return err
}
spinner.Message(msg + "...")

spinner.StopFailMessage(msg)
spinErr := spinner.StopFail()
if spinErr != nil {
return spinErr
}
}
return err
}

// In verbose mode we'll have the failure status AFTER the error output.
// But we can't just call StopMessage() without first starting the spinner.
if c.Globals.Flags.Verbose {
err = spinner.Start()
if err != nil {
return err
}
spinner.Message(msg + "...")
text.Break(out)
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
Expand Down