Skip to content

Commit

Permalink
Merge pull request #13 from devzero-inc/debo/no-prompt
Browse files Browse the repository at this point in the history
[lda] LDA_AUTO_UPDATE_CONFIG flag will not prompt the user and go with defaults
  • Loading branch information
dray92 authored Oct 3, 2024
2 parents 4ae7398 + ebff8bd commit d868d84
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -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
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
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 d868d84

Please sign in to comment.