Skip to content

Commit

Permalink
[lda] LDA_AUTO_UPDATE_CONFIG flag will not prompt the user and go wit…
Browse files Browse the repository at this point in the history
…h defaults
  • Loading branch information
dray92 committed Oct 3, 2024
1 parent 4ae7398 commit 07ae79c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
3 changes: 2 additions & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"embed"
"fmt"
"github.com/spf13/afero"
"html/template"
"lda/config"
"lda/util"
"os/exec"
"os/user"
"path/filepath"

"github.com/spf13/afero"

"github.com/rs/zerolog"
)

Expand Down
14 changes: 10 additions & 4 deletions shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ func (s *Shell) InjectShellSource() error {
}

if s.Config.IsRoot {
conf, err := promptForShellPath(shellConfigFile)
if err != nil {
return err
autoupdate := os.Getenv("LDA_AUTO_UPDATE_CONFIG")
// if user has set autoupdate in the env var, lets stick to installing in the default path for that shell
// so this logic will not prompt the user for shell info if autoupdate is set
// TODO support all shells for auto-update mechanisms
if !strings.EqualFold(autoupdate, "true") {
conf, err := promptForShellPath(shellConfigFile)
if err != nil {
return err
}
shellConfigFile = conf
}
shellConfigFile = conf
}

source, ok := sourceScripts[s.Config.ShellType]
Expand Down
28 changes: 18 additions & 10 deletions user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,30 @@ func ConfigureUserSystemInfo(currentConf *Config) {
diffMsg := strings.Join(diffs, "\n")
fmt.Fprintf(config.SysConfig.Out, "Differences detected in configuration:\n%s\n", diffMsg)

// Prompt user to choose between old and new config
prompt := promptui.Select{
Label: "Configuration drift detected. Do you want to update the configuration to the new settings?",
Items: []string{YesUpdate, NoKeep},
// allow for non-user interrupted flow
var result string
autoupdate := os.Getenv("LDA_AUTO_UPDATE_CONFIG")
if strings.EqualFold(autoupdate, "true") {
result = YesUpdate
}

_, result, err := prompt.Run()
// if no env vars, prompt the user
if result == "" {
// Prompt user to choose between old and new config
prompt := promptui.Select{
Label: "Configuration drift detected. Do you want to update the configuration to the new settings?",
Items: []string{YesUpdate, NoKeep},
}

if err != nil {
logging.Log.Error().Err(err).Msg("Prompt failed")
fmt.Fprintf(config.SysConfig.ErrOut, "Prompt failed: %s\n", err)
os.Exit(1)
_, result, err = prompt.Run()
if err != nil {
logging.Log.Error().Err(err).Msg("Prompt failed")
fmt.Fprintf(config.SysConfig.ErrOut, "Prompt failed: %s\n", err)
os.Exit(1)
}
}

if result == YesUpdate {

shellType, shellLocation, err := config.GetShell()
if err != nil {
logging.Log.Error().Err(err).Msg("Failed to setup shell")
Expand Down

0 comments on commit 07ae79c

Please sign in to comment.