Skip to content

Commit

Permalink
Add non interactive option
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzvonimir committed Oct 15, 2024
1 parent f9d00ac commit 5c750db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 5 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ var (
)

var installFlags struct {
shells []string
shells []string
nonInteractive bool
}

func newInstallCmd() *cobra.Command {
Expand All @@ -91,6 +92,8 @@ func newInstallCmd() *cobra.Command {

installCmd.Flags().StringSliceVarP(&installFlags.shells, "shell", "s", []string{}, fmt.Sprintf("Shells to instrument %+v; --shell=all for all shells", config.SupportedShells))

installCmd.Flags().BoolVarP(&installFlags.nonInteractive, "non-interactive", "n", false, "Run installation in non-interactive mode")

return installCmd
}

Expand Down Expand Up @@ -354,7 +357,7 @@ func install(cmd *cobra.Command, _ []string) error {
return errors.Wrap(err, "failed to install LDA shell configuration files")
}

if err := shl.InjectShellSource(); err != nil {
if err := shl.InjectShellSource(installFlags.nonInteractive); err != nil {
logging.Log.Error().Err(err).Msgf("Failed to inject shell source (%s); will reattempt at `start` time", shellLocation)
}
}
Expand Down
8 changes: 2 additions & 6 deletions shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *Shell) DeleteShellConfiguration() error {
}

// InjectShellSource injects the shell source
func (s *Shell) InjectShellSource() error {
func (s *Shell) InjectShellSource(nonInteractive bool) error {
s.logger.Info().Msg("Installing shell source")

var shellConfigFile string
Expand All @@ -175,11 +175,7 @@ func (s *Shell) InjectShellSource() error {
}

if s.Config.IsRoot {
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") {
if !nonInteractive {
conf, err := promptForShellPath(shellConfigFile)
if err != nil {
return err
Expand Down

0 comments on commit 5c750db

Please sign in to comment.