Skip to content

Commit

Permalink
fixed broken precedence for config, fixed typos, other minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
subfuzion committed Dec 30, 2016
1 parent 706445a commit 5d62b8e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions api/client/amp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (l logger) Println(args ...interface{}) {
// Configuration is for all configurable client settings
type Configuration struct {
Verbose bool
Github string
GitHub string
Target string
Port string
ServerAddress string
Expand Down Expand Up @@ -120,7 +120,7 @@ func (a *AMP) GetAuthorizedContext() (ctx context.Context, err error) {
// if a.Configuration.Github == "" {
// return nil, fmt.Errorf("Requires login")
// }
md := metadata.Pairs("sessionkey", a.Configuration.Github)
md := metadata.Pairs("sessionkey", a.Configuration.GitHub)
ctx = metadata.NewContext(context.Background(), md)
return
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/amp/cli/confighelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ func InitConfig(configFile string, config *client.Configuration, verbose bool, s
config.Verbose = verbose
config.ServerAddress = serverAddr

// Add matching environment variables - will be first in precedence.
// Add matching environment variables - will take precedence over config files.
viper.AutomaticEnv()

// Add config file specified using flag - will be next in precedence.
if configFile != "" {
viper.SetConfigFile(configFile)
}

// Add default config file (without extension) - will be last in precedence.
// First search .config/amp directory; if not found, then attempt to also search working
// directory (will only succeed if process was started from application directory).
// Add default config file search paths in order of increasing precedence.
viper.SetConfigName("amp")
viper.AddConfigPath("/etc/amp/")
if os.Getenv("XDG_CONFIG_HOME") != "" {
viper.AddConfigPath("$XDG_CONFIG_HOME/amp")
} else {
viper.AddConfigPath("$HOME/.config/amp")
}
viper.AddConfigPath("$HOME/.config/amp")
viper.AddConfigPath(".")

// config file specified using --use-config option will take precedence over other paths.
if configFile != "" {
viper.SetConfigFile(configFile)
}

// If a config file is found, read it in.
// Extra check for verbose because it might not have been set by
// a flag, but might be set in the config
Expand Down
2 changes: 1 addition & 1 deletion cmd/amp/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Login(a *client.AMP) error {
}
}

a.Configuration.Github = lastEight
a.Configuration.GitHub = lastEight
cli.SaveConfiguration(a.Configuration)

welcomeUser(name)
Expand Down
4 changes: 2 additions & 2 deletions cmd/amp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func main() {
RootCmd.SetUsageTemplate(usageTemplate)
RootCmd.SetHelpTemplate(helpTemplate)

RootCmd.PersistentFlags().StringVar(&configFile, "config", "", "Config file (default is $HOME/.config/amp/amp.yaml)")
RootCmd.PersistentFlags().BoolVar(&displayConfigFilePath, "config-file", false, "Display the location of the config file used (if any)")
RootCmd.PersistentFlags().StringVar(&configFile, "use-config", "", "Specify config file (overrides default at $HOME/.config/amp/amp.yaml)")
RootCmd.PersistentFlags().BoolVar(&displayConfigFilePath, "config-used", false, "Display config file used (if any)")
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output")
RootCmd.PersistentFlags().StringVar(&serverAddr, "server", "", "Server address")
RootCmd.PersistentFlags().BoolVarP(&listVersion, "version", "V", false, "Version number")
Expand Down
2 changes: 1 addition & 1 deletion cmd/amp/platform_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var PlatformStart = &cobra.Command{

func init() {
PlatformStart.Flags().BoolP("force", "f", false, "Start all possible services, do not stop on error")
PlatformStart.Flags().BoolP("quiet", "q", false, "Suppress terminal outpu")
PlatformStart.Flags().BoolP("quiet", "q", false, "Suppress terminal output")
PlatformStart.Flags().BoolP("local", "l", false, "Use local amp image")
PlatformCmd.AddCommand(PlatformStart)
}
Expand Down

0 comments on commit 5d62b8e

Please sign in to comment.