Skip to content

Commit

Permalink
Issue #190 Reviewing help system strings
Browse files Browse the repository at this point in the history
  • Loading branch information
thatdocslady authored and hferentschik committed Jan 10, 2017
1 parent 95795ad commit 629f261
Show file tree
Hide file tree
Showing 44 changed files with 302 additions and 295 deletions.
16 changes: 9 additions & 7 deletions cmd/minikube/cmd/config/config.go
Expand Up @@ -105,9 +105,11 @@ var settings []Setting = []Setting{

var ConfigCmd = &cobra.Command{
Use: "config SUBCOMMAND [flags]",
Short: "Modify minishift config",
Long: `config modifies minishift config files using subcommands like "minishift config set vm-driver kvm"
Configurable fields: ` + "\n\n" + configurableFields(),
Short: "Modifies Minishift configuration properties.",
Long: `Modifies Minishift configuration properties. Some of the configuration properties are equivalent
to the options that you set when you run the minishift start command.
Configurable properties (enter as SUBCOMMAND): ` + "\n\n" + configurableFields(),
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Expand All @@ -128,12 +130,12 @@ func ReadConfig() (MinikubeConfig, error) {
if os.IsNotExist(err) {
return make(map[string]interface{}), nil
}
return nil, fmt.Errorf("Could not open file %s: %s", constants.ConfigFile, err)
return nil, fmt.Errorf("Cannot open file %s: %s", constants.ConfigFile, err)
}
var m MinikubeConfig
m, err = decode(f)
if err != nil {
return nil, fmt.Errorf("Could not decode config %s: %s", constants.ConfigFile, err)
return nil, fmt.Errorf("Cannot decode config %s: %s", constants.ConfigFile, err)
}

return m, nil
Expand All @@ -143,12 +145,12 @@ func ReadConfig() (MinikubeConfig, error) {
func WriteConfig(m MinikubeConfig) error {
f, err := os.Create(constants.ConfigFile)
if err != nil {
return fmt.Errorf("Could not open file %s: %s", constants.ConfigFile, err)
return fmt.Errorf("Cannot create file %s: %s", constants.ConfigFile, err)
}
defer f.Close()
err = encode(f, m)
if err != nil {
return fmt.Errorf("Error encoding config %s: %s", constants.ConfigFile, err)
return fmt.Errorf("Cannot encode config %s: %s", constants.ConfigFile, err)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/config_test.go
Expand Up @@ -63,7 +63,7 @@ func TestReadConfig(t *testing.T) {
r := bytes.NewBufferString(tt.data)
config, err := decode(r)
if reflect.DeepEqual(config, tt.config) || err != nil {
t.Errorf("Did not read config correctly,\n\n wanted %+v, \n\n got %+v", tt.config, config)
t.Errorf("Cannot decode config. \n\n expected %+v, \n\n received %+v", tt.config, config)
}
}
}
Expand All @@ -76,7 +76,7 @@ func TestWriteConfig(t *testing.T) {
t.Errorf("Error encoding: %s", err)
}
if b.String() != tt.data {
t.Errorf("Did not write config correctly, \n\n expected:\n %+v \n\n actual:\n %+v", tt.data, b.String())
t.Errorf("Cannot encode config. \n\n expected \n %+v, \n\n received \n %+v", tt.data, b.String())
}
b.Reset()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/get.go
Expand Up @@ -25,8 +25,8 @@ import (

var configGetCmd = &cobra.Command{
Use: "get PROPERTY_NAME",
Short: "Gets the value of PROPERTY_NAME from the minishift config file",
Long: "Returns the value of PROPERTY_NAME from the minishift config file. Can be overwritten at runtime by flags or environmental variables.",
Short: "Gets the value of a configuration property from the Minishift configuration file.",
Long: "Gets the value of a configuration property from the minishift configuration file. This value can be overwritten at runtime by flags or environmental variables.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "usage: minishift config get PROPERTY_NAME")
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/set.go
Expand Up @@ -25,9 +25,9 @@ import (

var configSetCmd = &cobra.Command{
Use: "set PROPERTY_NAME PROPERTY_VALUE",
Short: "Sets an individual value in a minishift config file",
Long: `Sets the PROPERTY_NAME config value to PROPERTY_VALUE
These values can be overwritten by flags or environment variables at runtime.`,
Short: "Sets the value of a configuration property in the Minishift configuration file.",
Long: `Sets the value of one or more configuration properties in the Minishift configuration file.
These values can be overwritten by flags or environment variables at runtime.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
fmt.Fprintln(os.Stderr, "usage: minishift config set PROPERTY_NAME PROPERTY_VALUE")
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/unset.go
Expand Up @@ -25,8 +25,8 @@ import (

var configUnsetCmd = &cobra.Command{
Use: "unset PROPERTY_NAME",
Short: "unsets an individual value in a minishift config file",
Long: "unsets PROPERTY_NAME from the minishift config file. Can be overwritten by flags or environmental variables",
Short: "Clears the value of a configuration property in the Minishift configuration file.",
Long: "Clears the value of a configuration property in the Minishift configuration file. The value can be overwritten at runtime by flags or environment variables",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Fprintf(os.Stdout, "usage: minishift config unset PROPERTY_NAME")
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/util.go
Expand Up @@ -43,7 +43,7 @@ func findSetting(name string) (Setting, error) {
return s, nil
}
}
return Setting{}, fmt.Errorf("Property name %s not found", name)
return Setting{}, fmt.Errorf("Cannot find property name %s", name)
}

// Set Functions
Expand Down
20 changes: 10 additions & 10 deletions cmd/minikube/cmd/config/util_test.go
Expand Up @@ -27,51 +27,51 @@ var minikubeConfig = MinikubeConfig{
func TestFindSettingNotFound(t *testing.T) {
s, err := findSetting("nonexistant")
if err == nil {
t.Fatalf("Shouldn't have found setting, but did. [%+v]", s)
t.Fatalf("Unexpected setting found. [%+v]", s)
}
}

func TestFindSetting(t *testing.T) {
s, err := findSetting("vm-driver")
if err != nil {
t.Fatalf("Couldn't find setting, vm-driver: %s", err)
t.Fatalf("Cannot find the setting of the vm-driver: %s", err)
}
if s.name != "vm-driver" {
t.Fatalf("Found wrong setting, expected vm-driver, got %s", s.name)
t.Fatalf("Incorrect setting, expected vm-driver, received %s", s.name)
}
}

func TestSetString(t *testing.T) {
err := SetString(minikubeConfig, "vm-driver", "virtualbox")
if err != nil {
t.Fatalf("Couldnt set string: %s", err)
t.Fatalf("Cannot set the string: %s", err)
}
}

func TestSetInt(t *testing.T) {
err := SetInt(minikubeConfig, "cpus", "22")
if err != nil {
t.Fatalf("Couldn't set int in config: %s", err)
t.Fatalf("Cannot set integer value in config: %s", err)
}
val, ok := minikubeConfig["cpus"].(int)
if !ok {
t.Fatalf("Type not set to int")
t.Fatalf("Type is not set to int")
}
if val != 22 {
t.Fatalf("SetInt set wrong value")
t.Fatalf("SetInt set value is incorrect")
}
}

func TestSetBool(t *testing.T) {
err := SetBool(minikubeConfig, "show-libmachine-logs", "true")
if err != nil {
t.Fatalf("Couldn't set bool in config: %s", err)
t.Fatalf("Cannot set boolean value in config: %s", err)
}
val, ok := minikubeConfig["show-libmachine-logs"].(bool)
if !ok {
t.Fatalf("Type not set to bool")
t.Fatalf("Type is not set to bool")
}
if !val {
t.Fatalf("SetBool set wrong value")
t.Fatalf("SetBool set value is incorrect")
}
}
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/validations.go
Expand Up @@ -37,14 +37,14 @@ func IsValidDriver(string, driver string) error {
}

func RequiresRestartMsg(string, string) error {
fmt.Fprintln(os.Stdout, "These changes will take effect upon a minishift delete and then a minishift start")
fmt.Fprintln(os.Stdout, "To apply the changes, you must delete the current VM with `minishift delete` and start a new VM with `minishift start`.")
return nil
}

func IsValidDiskSize(name string, disksize string) error {
_, err := units.FromHumanSize(disksize)
if err != nil {
return fmt.Errorf("Not valid disk size: %v", err)
return fmt.Errorf("Disk size is not valid: %v", err)
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/config/view.go
Expand Up @@ -36,8 +36,8 @@ type ConfigViewTemplate struct {

var configViewCmd = &cobra.Command{
Use: "view",
Short: "Display values currently set in the minishift config file",
Long: "Display values currently set in the minishift config file.",
Short: "Display the properties and values of the Minishift configuration file.",
Long: "Display the properties and values of the Minishift configuration file. You can set the output format from one of the available Go templates.",
Run: func(cmd *cobra.Command, args []string) {
err := configView()
if err != nil {
Expand All @@ -49,8 +49,8 @@ var configViewCmd = &cobra.Command{

func init() {
configViewCmd.Flags().StringVar(&configViewFormat, "format", constants.DefaultConfigViewFormat,
`Go template format string for the config view output. The format for Go templates can be found here: https://golang.org/pkg/text/template/
For the list of accessible variables for the template, see the struct values here: https://godoc.org/github.com/jimmidyson/minishift/cmd/minikube/cmd/config#ConfigViewTemplate`)
`Go template format to apply to the configuration file. For more information about Go templates, see: https://golang.org/pkg/text/template/
For the list of configurable variables for the template, see the struct values section of ConfigViewTemplate at: https://godoc.org/github.com/minishift/minishift/cmd/minikube/cmd/config#ConfigViewTemplate`)
}

func init() {
Expand Down
10 changes: 5 additions & 5 deletions cmd/minikube/cmd/console.go
Expand Up @@ -35,26 +35,26 @@ var (
// consoleCmd represents the console command
var consoleCmd = &cobra.Command{
Use: "console",
Short: "Opens/displays the OpenShift console URL for your local cluster",
Long: `Opens/displays the OpenShift console URL for your local cluster`,
Short: "Opens the OpenShift Web console to the root of your local cluster.",
Long: `Opens the OpenShift Web console to the root of your local cluster in the default browser.`,
Run: func(cmd *cobra.Command, args []string) {
api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
defer api.Close()
url, err := cluster.GetConsoleURL(api)
if err != nil {
glog.Errorln("Error accessing the OpenShift console (is minishift running?): Error: ", err)
glog.Errorln("Cannot access the OpenShift console. Verify that Minishift is running. Error: ", err)
os.Exit(1)
}
if consoleURLMode {
fmt.Fprintln(os.Stdout, url)
} else {
fmt.Fprintln(os.Stdout, "Opening OpenShift console in default browser...")
fmt.Fprintln(os.Stdout, "Opening the OpenShift Web console in the default browser...")
browser.OpenURL(url)
}
},
}

func init() {
consoleCmd.Flags().BoolVar(&consoleURLMode, "url", false, "Display the OpenShift console in the CLI instead of opening it in the default browser")
consoleCmd.Flags().BoolVar(&consoleURLMode, "url", false, "Open the local cluster in the OpenShift CLI console instead of the Web console.")
RootCmd.AddCommand(consoleCmd)
}
15 changes: 7 additions & 8 deletions cmd/minikube/cmd/delete.go
Expand Up @@ -32,32 +32,31 @@ import (
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a local OpenShift cluster.",
Long: `Deletes a local OpenShift cluster. This command deletes the VM, and removes all
associated files.`,
Short: "Deletes the Minishift VM.",
Long: `Deletes the Minishift VM, including the local OpenShift cluster and all associated files.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Deleting local OpenShift instance...")
fmt.Println("Deleting the Minishift VM...")
api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
defer api.Close()
host, err := api.Load(constants.MachineName)
if err != nil {
fmt.Println("Error occurred deleting machine: ", err)
fmt.Println("Error occurred while deleting the VM: ", err)
os.Exit(1)
}

if !drivers.MachineInState(host.Driver, state.Stopped)() {
// Unregister Host VM
if err := registration.UnregisterHostVM(host, RegistrationParameters); err != nil {
fmt.Printf("Error unregistring machine: %s", err)
fmt.Printf("Error unregistring the VM: %s", err)
os.Exit(1)
}
}

if err := cluster.DeleteHost(api); err != nil {
fmt.Println("Errors occurred deleting machine: ", err)
fmt.Println("Error deleting the VM: ", err)
os.Exit(1)
}
fmt.Println("Machine deleted.")
fmt.Println("Minishift VM deleted.")
},
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/minikube/cmd/env.go
Expand Up @@ -224,8 +224,8 @@ func findNoProxyFromEnv() (string, string) {
// envCmd represents the docker-env command
var dockerEnvCmd = &cobra.Command{
Use: "docker-env",
Short: "sets up docker env variables; similar to '$(docker-machine env)'",
Long: `sets up docker env variables; similar to '$(docker-machine env)'`,
Short: "Sets Docker environment variables.",
Long: `Sets Docker environment variables, similar to '$(docker-machine env)'.`,
Run: func(cmd *cobra.Command, args []string) {

api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
Expand All @@ -239,13 +239,13 @@ var dockerEnvCmd = &cobra.Command{
if unset {
shellCfg, err = shellCfgUnset(api)
if err != nil {
glog.Errorln("Error setting machine env variable(s):", err)
glog.Errorln("Error unsetting environment variables:", err)
os.Exit(1)
}
} else {
shellCfg, err = shellCfgSet(api)
if err != nil {
glog.Errorln("Error setting machine env variable(s):", err)
glog.Errorln("Error setting environment variables:", err)
os.Exit(1)
}
}
Expand All @@ -256,7 +256,7 @@ var dockerEnvCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(dockerEnvCmd)
dockerEnvCmd.Flags().BoolVar(&noProxy, "no-proxy", false, "Add machine IP to NO_PROXY environment variable")
dockerEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect")
dockerEnvCmd.Flags().BoolVarP(&unset, "unset", "u", false, "Unset variables instead of setting them")
dockerEnvCmd.Flags().BoolVar(&noProxy, "no-proxy", false, "Add the virtual machine IP to the NO_PROXY environment variable.")
dockerEnvCmd.Flags().StringVar(&forceShell, "shell", "", "Force setting the environment for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh]. Default is auto-detect.")
dockerEnvCmd.Flags().BoolVarP(&unset, "unset", "u", false, "Clear the environment variable values instead of setting them.")
}
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/get_openshift_versions.go
Expand Up @@ -26,8 +26,8 @@ import (
// getVersionsCmd represents the ip command
var getVersionsCmd = &cobra.Command{
Use: "get-openshift-versions",
Short: "Gets the list of available OpenShift versions available for minishift.",
Long: `Gets the list of available OpenShift versions available for minishift.`,
Short: "Gets the list of OpenShift versions available for Minishift.",
Long: `Gets the list of OpenShift versions available for Minishift.`,
Run: func(cmd *cobra.Command, args []string) {
openshiftversions.PrintOpenShiftVersionsFromGitHub(os.Stdout)
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/ip.go
Expand Up @@ -30,8 +30,8 @@ import (
// ipCmd represents the ip command
var ipCmd = &cobra.Command{
Use: "ip",
Short: "Retrieve the IP address of the running cluster.",
Long: `Retrieves the IP address of the running cluster, and writes it to STDOUT.`,
Short: "Gets the IP address of the running cluster.",
Long: `Gets the IP address of the running cluster and prints it to the standard output.`,
Run: func(cmd *cobra.Command, args []string) {
api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
defer api.Close()
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/logs.go
Expand Up @@ -30,14 +30,14 @@ import (
// logsCmd represents the logs command
var logsCmd = &cobra.Command{
Use: "logs",
Short: "Gets the logs of the running OpenShift instance, used for debugging minishift, not user code.",
Long: `Gets the logs of the running OpenShift instance, used for debugging minishift, not user code.`,
Short: "Gets the logs of the running OpenShift cluster.",
Long: `Gets the logs of the running OpenShift cluster. The logs do not contain information about your application code.`,
Run: func(cmd *cobra.Command, args []string) {
api := libmachine.NewClient(constants.Minipath, constants.MakeMiniPath("certs"))
defer api.Close()
s, err := cluster.GetHostLogs(api)
if err != nil {
log.Println("Error getting machine logs:", err)
log.Println("Error getting logs:", err)
os.Exit(1)
}
fmt.Fprintln(os.Stdout, s)
Expand Down
10 changes: 5 additions & 5 deletions cmd/minikube/cmd/root.go
Expand Up @@ -66,8 +66,8 @@ var viperWhiteList = []string{
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "minishift",
Short: "Minishift is a tool for managing local OpenShift clusters.",
Long: `Minishift is a CLI tool that provisions and manages single-node OpenShift clusters optimized for development workflows.`,
Short: "Minishift is a tool for application development in local OpenShift clusters.",
Long: `Minishift is a command-line tool that provisions and manages single-node OpenShift clusters optimized for development workflows.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
for _, path := range dirs {
if err := os.MkdirAll(path, 0777); err != nil {
Expand Down Expand Up @@ -112,9 +112,9 @@ func setFlagsUsingViper() {
}

func init() {
RootCmd.PersistentFlags().Bool(showLibmachineLogs, false, "Whether or not to show logs from libmachine.")
RootCmd.PersistentFlags().String(username, "", "Username to register Virtual Machine")
RootCmd.PersistentFlags().String(password, "", "Password to register Virtual Machine")
RootCmd.PersistentFlags().Bool(showLibmachineLogs, false, "Show logs from libmachine.")
RootCmd.PersistentFlags().String(username, "", "User name for the virtual machine.")
RootCmd.PersistentFlags().String(password, "", "Password for the virtual machine.")
RootCmd.AddCommand(configCmd.ConfigCmd)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
logDir := pflag.Lookup("log_dir")
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/root_test.go
Expand Up @@ -94,7 +94,7 @@ func TestViperConfig(t *testing.T) {
defer viper.Reset()
err := cli.InitTestConfig(`{ "v": "999" }`)
if viper.GetString("v") != "999" || err != nil {
t.Fatalf("Viper did not read test config file: %v", err)
t.Fatalf("Viper cannot read the test config file: %v", err)
}
}

Expand All @@ -106,7 +106,7 @@ func TestViperAndFlags(t *testing.T) {
setupViper()
f := pflag.Lookup(testOption.Name)
if f == nil {
t.Fatalf("Could not find flag for %s", testOption.Name)
t.Fatalf("Cannot find the flag for %s", testOption.Name)
}
actual := f.Value.String()
if actual != testOption.ExpectedValue {
Expand Down

0 comments on commit 629f261

Please sign in to comment.