Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Sep 1, 2020
1 parent e5042df commit ad11429
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 50 deletions.
35 changes: 0 additions & 35 deletions internal/commands/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,6 @@ the login command with the --tenant and --region flag:
return ""
}

func getUsageTemplate() string {
return fmt.Sprintf(`%s{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} <resource> <operation> [parameters...]{{end}}{{if gt (len .Aliases) 0}}
%s
{{.NameAndAliases}}{{end}}{{if .HasExample}}
%s
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}
%s{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
%s
{{WrappedLocalFlagUsages . | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
%s
{{WrappedInheritedFlagUsages . | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
%s{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`,
ansi.Faint("Usage:"),
ansi.Faint("Aliases:"),
ansi.Faint("Examples:"),
ansi.Faint("Available Resources:"),
ansi.Faint("Flags:"),
ansi.Faint("Global Flags:"),
ansi.Faint("Additional help topics:"),
)
}

func namespaceUsageTemplate() string {
return fmt.Sprintf(`%s{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
Expand Down
6 changes: 5 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,13 @@ func isProfile(value interface{}) bool {

// syncConfig merges a runtimeViper instance with the config file being used.
func syncConfig(runtimeViper *viper.Viper) error {
runtimeViper.MergeInConfig()
if err := runtimeViper.MergeInConfig(); err != nil {
return err
}

profilesFile := viper.ConfigFileUsed()
runtimeViper.SetConfigFile(profilesFile)

// Ensure we preserve the config file type
runtimeViper.SetConfigType(filepath.Ext(profilesFile))

Expand Down
17 changes: 3 additions & 14 deletions internal/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ func (p *Profile) writeProfile(runtimeViper *viper.Viper) error {
runtimeViper.Set(p.GetConfigField("device_name"), strings.TrimSpace(p.DeviceName))
}

runtimeViper.MergeInConfig()
if err := runtimeViper.MergeInConfig(); err != nil {
return err
}

runtimeViper.SetConfigFile(profilesFile)

Expand All @@ -165,16 +167,3 @@ func (p *Profile) writeProfile(runtimeViper *viper.Viper) error {

return nil
}

func (p *Profile) safeRemove(v *viper.Viper, key string) *viper.Viper {
if v.IsSet(p.GetConfigField(key)) {
newViper, err := removeKey(v, p.GetConfigField(key))
if err == nil {
// I don't want to fail the entire login process on not being able to remove
// the old secret_key field so if there's no error
return newViper
}
}

return v
}

0 comments on commit ad11429

Please sign in to comment.