Skip to content

Commit

Permalink
Merge pull request #657 from newrelic/removeAdvanced
Browse files Browse the repository at this point in the history
chore(install): remove advanced mode
  • Loading branch information
zlesnr authored Feb 5, 2021
2 parents e5e63fa + 3e64fdc commit ab1d4f1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 96 deletions.
3 changes: 0 additions & 3 deletions internal/install/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

var (
assumeYes bool
advancedMode bool
recipeNames []string
recipePaths []string
skipDiscovery bool
Expand All @@ -33,7 +32,6 @@ var Command = &cobra.Command{
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
ic := InstallerContext{
AdvancedMode: advancedMode,
AssumeYes: assumeYes,
RecipeNames: recipeNames,
RecipePaths: recipePaths,
Expand Down Expand Up @@ -85,5 +83,4 @@ func init() {
Command.Flags().BoolVar(&debug, "debug", false, "debug level logging")
Command.Flags().BoolVar(&trace, "trace", false, "trace level logging")
Command.Flags().BoolVarP(&assumeYes, "assumeYes", "y", false, "use \"yes\" for all questions during install")
Command.Flags().BoolVarP(&advancedMode, "advanced", "", false, "use \"advanced\" mode")
}
2 changes: 1 addition & 1 deletion internal/install/discovery/glob_file_filterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGlobFileFilter(t *testing.T) {
ID: "nginx",
LogMatch: []types.LogMatch{
{
File: "/var/log/nginx/*.log",
File: "/var/log/nope/*.log",
},
},
},
Expand Down
6 changes: 0 additions & 6 deletions internal/install/install_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package install

// nolint: maligned
type InstallerContext struct {
AdvancedMode bool
AssumeYes bool
RecipeNames []string
RecipePaths []string
Expand Down Expand Up @@ -39,8 +38,3 @@ func (i *InstallerContext) RecipeNamesProvided() bool {
func (i *InstallerContext) RecipesProvided() bool {
return i.RecipePathsProvided() || i.RecipeNamesProvided()
}

// ShouldPrompt determines if the user should be prompted for input.
func (i *InstallerContext) ShouldPrompt() bool {
return i.AdvancedMode
}
36 changes: 0 additions & 36 deletions internal/install/install_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,6 @@ func TestShouldInstallLogging_RecipePathsProvided(t *testing.T) {
require.True(t, ic.ShouldInstallIntegrations())
}

func TestShouldPrompt(t *testing.T) {
cases := []struct {
ctx InstallerContext
expected bool
}{
{
ctx: InstallerContext{},
expected: false,
},
{
ctx: InstallerContext{
AdvancedMode: true,
},
expected: true,
},
{
ctx: InstallerContext{
AssumeYes: true,
},
expected: false,
},
{
ctx: InstallerContext{
RecipeNames: []string{"namegoeshere"},
},
expected: false,
},
}

for _, tc := range cases {
if tc.expected != tc.ctx.ShouldPrompt() {
t.Errorf("expected ShouldPrompt()=%t with context: %+v", tc.expected, tc.ctx)
}
}
}

func TestRecipeNamesProvided(t *testing.T) {
ic := InstallerContext{}

Expand Down
52 changes: 8 additions & 44 deletions internal/install/recipe_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (i *RecipeInstaller) Install() error {
"ShouldInstallInfraAgent": i.ShouldInstallInfraAgent(),
"ShouldInstallLogging": i.ShouldInstallLogging(),
"ShouldInstallIntegrations": i.ShouldInstallIntegrations(),
"ShouldPrompt": i.ShouldPrompt(),
"RecipesProvided": i.RecipesProvided(),
"RecipePathsProvided": i.RecipePathsProvided(),
"RecipeNamesProvided": i.RecipeNamesProvided(),
Expand Down Expand Up @@ -305,38 +304,21 @@ func (i *RecipeInstaller) installRecipes(m *types.DiscoveryManifest, recipes []t
}
}

var ok bool
var err error

ok, err = i.userAcceptsInstall(r)
if err != nil {
return fmt.Errorf("error prompting user: %s", err)
}

log.WithFields(log.Fields{
"accepted": ok,
}).Debug("done prompting for install")

if ok {
log.WithFields(log.Fields{
"name": r.Name,
}).Debug("installing recipe")
"name": r.Name,
}).Debug("installing recipe")

_, err = i.executeAndValidateWithProgress(m, &r)
if err != nil {
log.Debugf("Failed while executing and validating with progress for recipe name %s, detail:%s", r.Name, err)
log.Warn(err)
log.Warn(i.failMessage(r.Name))
}
log.Debugf("Done executing and validating with progress for recipe name %s.", r.Name)
} else {
i.status.ReportRecipeSkipped(execution.RecipeStatusEvent{
Recipe: r,
})
_, err = i.executeAndValidateWithProgress(m, &r)
if err != nil {
log.Debugf("Failed while executing and validating with progress for recipe name %s, detail:%s", r.Name, err)
log.Warn(err)
log.Warn(i.failMessage(r.Name))
}
log.Debugf("Done executing and validating with progress for recipe name %s.", r.Name)
}

log.Debug("Done installing recipes with prompts")
return nil
}

Expand Down Expand Up @@ -563,28 +545,10 @@ func (i *RecipeInstaller) userAccepts(msg string) (bool, error) {
}

func (i *RecipeInstaller) userAcceptsLogFile(match types.LogMatch) (bool, error) {
if !i.ShouldPrompt() {
return true, nil
}

msg := fmt.Sprintf("Files have been found at the following pattern: %s Do you want to watch them?", match.File)
return i.userAccepts(msg)
}

func (i *RecipeInstaller) userAcceptsInstall(r types.Recipe) (bool, error) {
if !i.ShouldPrompt() {
return true, nil
}

log.WithFields(log.Fields{
"name": r.Name,
"display_name": r.DisplayName,
}).Debug("prompting user for install confirmation")

msg := fmt.Sprintf("Would you like to enable %s?", r.DisplayName)
return i.userAccepts(msg)
}

func (i *RecipeInstaller) fail(err error) error {
i.status.ReportComplete()
return err
Expand Down
10 changes: 4 additions & 6 deletions internal/install/recipe_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ func TestInstall_ReportRecipeSkipped_skipping_integrations(t *testing.T) {

func TestInstall_ReportRecipeSkipped_multiselect(t *testing.T) {
ic := InstallerContext{
// SkipInfraInstall: true,
// SkipLoggingInstall: true,
SkipInfraInstall: true,
SkipLoggingInstall: true,
}
statusReporters = []execution.StatusReporter{execution.NewMockStatusReporter()}
status = execution.NewStatusRollup(statusReporters)
Expand All @@ -285,7 +285,7 @@ func TestInstall_ReportRecipeSkipped_multiselect(t *testing.T) {

v = validation.NewMockRecipeValidator()
p = &ux.MockPrompter{
PromptYesNoVal: false,
PromptYesNoVal: true,
PromptMultiSelectVal: []string{testRecipeName},
}

Expand All @@ -298,9 +298,7 @@ func TestInstall_ReportRecipeSkipped_multiselect(t *testing.T) {
}

func TestInstallAdvancedMode_bounce_on_enter(t *testing.T) {
ic := InstallerContext{
AdvancedMode: true,
}
ic := InstallerContext{}
statusReporters = []execution.StatusReporter{execution.NewMockStatusReporter()}
status = execution.NewStatusRollup(statusReporters)
f = recipes.NewMockRecipeFetcher()
Expand Down

0 comments on commit ab1d4f1

Please sign in to comment.