From 07ae79c0a79c467f4c52550ad0f0ac02f424235f Mon Sep 17 00:00:00 2001 From: Debosmit Ray Date: Thu, 3 Oct 2024 01:03:54 +0000 Subject: [PATCH 1/2] [lda] LDA_AUTO_UPDATE_CONFIG flag will not prompt the user and go with defaults --- daemon/daemon.go | 3 ++- shell/shell.go | 14 ++++++++++---- user/user.go | 28 ++++++++++++++++++---------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 827d477..40f9849 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -4,7 +4,6 @@ import ( "bytes" "embed" "fmt" - "github.com/spf13/afero" "html/template" "lda/config" "lda/util" @@ -12,6 +11,8 @@ import ( "os/user" "path/filepath" + "github.com/spf13/afero" + "github.com/rs/zerolog" ) diff --git a/shell/shell.go b/shell/shell.go index 57490e7..60da233 100644 --- a/shell/shell.go +++ b/shell/shell.go @@ -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] diff --git a/user/user.go b/user/user.go index 4fc69ed..3f2209a 100644 --- a/user/user.go +++ b/user/user.go @@ -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") From ebff8bdcef0a8263e412764e69c03e9aca76511c Mon Sep 17 00:00:00 2001 From: Debosmit Ray Date: Thu, 3 Oct 2024 14:12:31 +0000 Subject: [PATCH 2/2] go mod tidy --- go.mod | 3 ++- go.sum | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 19e12d9..e44080d 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module lda go 1.21.4 require ( + connectrpc.com/connect v1.17.0 github.com/jmoiron/sqlx v1.3.5 github.com/manifoldco/promptui v0.9.0 github.com/mattn/go-sqlite3 v1.14.22 @@ -14,6 +15,7 @@ require ( github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.59.0 + google.golang.org/protobuf v1.34.2 ) require ( @@ -46,7 +48,6 @@ require ( golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect - google.golang.org/protobuf v1.33.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ae0b56f..3734f05 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk= +connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= @@ -123,8 +125,8 @@ google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=