Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add config command for toggling update checker #589

Merged
merged 2 commits into from
Sep 4, 2018

Conversation

syamgk
Copy link
Member

@syamgk syamgk commented Jul 18, 2018

  • add config command
  • create a new field 'config' in odoconfig file
    for storing odo specific configurations

@syamgk syamgk added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. Required by Prow. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. labels Jul 18, 2018
@syamgk syamgk mentioned this pull request Jul 19, 2018
@syamgk syamgk force-pushed the odo-config branch 5 times, most recently from 928fe24 to ce89cb3 Compare July 23, 2018 06:32
@syamgk syamgk removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. Required by Prow. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. labels Jul 23, 2018
@syamgk syamgk force-pushed the odo-config branch 2 times, most recently from 58e04d7 to 37228d3 Compare July 23, 2018 07:20
@syamgk syamgk changed the title add config command add config command for toggling update checker Jul 23, 2018
@surajnarwade
Copy link
Contributor

@syamgk , there's a problem

✔ ~/go/src/github.com/redhat-developer/odo [pr_589 L|⚑ 29] 
17:12 $ odo config set UpdateNotification false
✔ ~/go/src/github.com/redhat-developer/odo [pr_589 L|⚑ 29] 
17:12 $ odo config get
{UpdateNotification:true}

@syamgk
Copy link
Member Author

syamgk commented Jul 24, 2018

good catch @surajnarwade
the yaml.unmashal is not working as I thought
am on this, finding a way to make it 'true' in case not specified on odo file

cmd/config.go Outdated
var configurationCmd = &cobra.Command{
Use: "config",
Short: "Modifying configuration settings",
Long: `Performs edits on configuration settings on config file.`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Change configuration values" or something like that might be better.
Regular ODO user doesn't have to know anything about config file.

configFileName = "odo"
)

// ConfigurationInfo holds all odo specific configurations
type ConfigurationInfo struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit confusing name. We already have ConfigInfo that is root struct for the whole odo config handling.

@@ -16,6 +16,11 @@ const (
configFileName = "odo"
)

// ConfigurationInfo holds all odo specific configurations
type ConfigurationInfo struct {
UpdateNotification bool `json:"updatenotification"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this pointer to bool to make it possible to detect whatever it was set or not.

@@ -112,6 +120,46 @@ func (c *ConfigInfo) writeToFile() error {
return nil
}

// SetConfiguration Set Odo configurations
func SetConfiguration(component string, value bool) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is component it is not used inside this function

}

// GetupdateNotificationStatus returns the value of UpdateNotification config
func GetupdateNotificationStatus() bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between this and GetConfiguration?
It looks like they are both doing almost the same.


// Getconfiguration get odo configurations
func GetConfiguration() error {
cfg, err := New()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't call New() here. Check other function in this file, and try to follow the same pattern in your functions.

cmd/config.go Outdated
}
}, Run: func(cmd *cobra.Command, args []string) {

switch args[1] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use strconv.ParseBool to avoid this switch case and make the code more robust.

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments

cmd/config.go Outdated
var configurationCmd = &cobra.Command{
Use: "config",
Short: "Modifies configuration settings",
Long: `Modifies odo specific configuration settings on config file.`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe: Modifies Odo specific configuration settings within the config file?

cmd/config.go Outdated
// 'odo config' is the same as 'odo config get'
Args: func(cmd *cobra.Command, args []string) error {
if len(args) >= 1 && (args[0] != "get" || args[0] != "set") {
return fmt.Errorf("Unknown usage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unknown usage? Maybe Unknown command, use set or get

cmd/config.go Outdated
var configurationSetCmd = &cobra.Command{
Use: "set",
Short: "Set a value in odo config file",
Long: "Set an individual value in odo configuration file",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the Odo configuration file

cmd/config.go Outdated
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return fmt.Errorf("Please provide parameter name and value")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a

cmd/config.go Outdated
if len(args) < 2 {
return fmt.Errorf("Please provide parameter name and value")
} else if len(args) > 2 {
return fmt.Errorf("Only one value per parameter name is allowed")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove name

@@ -112,6 +120,46 @@ func (c *ConfigInfo) writeToFile() error {
return nil
}

// SetConfiguration Set Odo configurations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use a better description

cfg.OdoConfigurations.UpdateNotification = value
err = cfg.writeToFile()
if err != nil {
return errors.Wrapf(err, "unable to set updatenotification to %t ", value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add spacing between update notification

func SetConfiguration(component string, value bool) error {
cfg, err := New()
if err != nil {
return errors.Wrap(err, "unable to modify configuration")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe unable to modify configuration file ? this modifies an actual file, right?

return nil
}

// Getconfiguration get odo configurations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More descriptive configuration :)

@syamgk syamgk force-pushed the odo-config branch 4 times, most recently from 9b40e33 to 33dcd32 Compare July 31, 2018 18:37
@syamgk syamgk force-pushed the odo-config branch 2 times, most recently from 096374f to d4df9d5 Compare August 6, 2018 11:44
Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepts any wrong value and updates the UpdateNotification's value

cmd/config.go Outdated
if err != nil {
fmt.Println(err, "unable to set configuration")
}
cfg.SetConfiguration(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are two values that can be updated then there is no check for that. Also if there is a spelling mistake or any other value, then it updates the UpdateNotification value only.

[mdas@localhost odo]$ ./odo config set dajsdion true
[mdas@localhost odo]$ 

The above shouldn't update UpdateNotification's value

cmd/config.go Outdated
configurationGetCmd.Example,
configurationSetCmd.Example),
Aliases: []string{"configuration"},
// 'odo config' is the same as 'odo config get'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odo utils config ;-)

cmd/config.go Outdated
}

var configurationGetCmd = &cobra.Command{
Use: "get",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to name this command view? as it lists all the values in config.
I would image that get will allow me to get a value of the configuration option that I specify like odo utils config get updatenotification.

We don't have to implement this right now. But I would prefer renaming this command to view to better match its behavior. WDYT?

cmd/config.go Outdated

var configurationGetCmd = &cobra.Command{
Use: "get",
Short: "View current value",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View current values. might be better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okey

cmd/utils.go Outdated
configurationCmd.AddCommand(configurationSetCmd)

// Add a defined annotation in order to appear in the help menu
//configurationCmd.Annotations = map[string]string{"command": "utility"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can delete those comments

cmd/config.go Outdated
@@ -68,16 +68,16 @@ var configurationSetCmd = &cobra.Command{
}

var configurationGetCmd = &cobra.Command{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable should be also renamed

@surajnarwade
Copy link
Contributor

Check minishift config

$ minishift config
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): 

 * iso-url
 * cpus
 * memory
..........
...........
 * hyperv-virtual-switch

Usage:
  minishift config SUBCOMMAND [flags]
  minishift config [command]

Available Commands:
  get         Gets the value of a configuration property from the Minishift configuration file.
  set         Sets the value of a configuration property in the Minishift configuration file.
  unset       Clears the value of a configuration property in the Minishift configuration file.
  view        Display the properties and values of the Minishift configuration file.

Flags:
  -h, --help   help for config

Global Flags:
      --alsologtostderr                  log to standard error as well as files
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory
      --logtostderr                      log to standard error instead of files
      --profile string                   Profile name (default "minishift")
      --show-libmachine-logs             Show logs from libmachine.
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
  -v, --v Level                          log level for V logs. Level varies from 1 to 5 (default 1).
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

Use "minishift config [command] --help" for more information about a command.

I think we should follow this for odo utls config, as of now, odo utils config and odo utils config view are the same

✔ ~/go/src/github.com/redhat-developer/odo [pr_589 L|⚑ 33] 
09:04 $ odo utils config
PARAMETER             CURRENTVALUE
UpdateNotification    true
✔ ~/go/src/github.com/redhat-developer/odo [pr_589 L|⚑ 33] 
09:23 $ odo utils config view
PARAMETER             CURRENTVALUE
UpdateNotification    true

@surajnarwade surajnarwade added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 24, 2018
@kadel
Copy link
Member

kadel commented Aug 24, 2018

@surajnarwade Agreed odo utils config should just show help message

@syamgk can you please rebase this and

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odo utils config is not a blocker we can fix it in another PR.

It is up to you @surajnarwade ;-)

@syamgk
Copy link
Member Author

syamgk commented Aug 24, 2018

@surajnarwade changed odo utils config to print the help message

@kadel rebased the PR

If everything looks good I can squash the commit and update the commit message

@syamgk syamgk removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 24, 2018
Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no e2e tests for this :(

Since this is a new command, it's suggested that we add one even if it's super simple.

Have a look at my comments however!

cmd/config.go Outdated
# Available Parameters:
UpdateNotification - Controls if an update notification is shown or not (true or false)`,
Example: ` # Set a configuration value
odo utils config set UpdateNotification false`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add a newline:

example:

odo utils config set UpdateNotification false
`,

cmd/config.go Outdated
# Available Parameters:
UpdateNotification - Controls if an update notification is shown or not (true or false)`,
Example: ` # Set a configuration value
odo utils config set UpdateNotification false`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something weird is happening here too. it it 3-spaces not 1-tab, as it is not appearing aligned:

github.com/redhat-developer/odo  pr_589 ✔                                                                                                                                                                                                                                   3d  ⍉
▶ ./odo utils
Utilities for completion, terminal commands and modifying Odo configurations

Usage:
  odo utils [command]

Examples:
  # Bash autocompletion support
  source <(odo utils completion bash)

  # Zsh autocompletion support
  source <(odo utils completion zsh)

  # Bash terminal PS1 support
  source <(odo utils terminal bash)

  # Zsh terminal PS1 support
  source <(odo utils terminal zsh)

  # Set a configuration value
    odo utils config set UpdateNotification false
  # For viewing the current configuration
    odo utils config view

cmd/config.go Outdated

var configurationViewCmd = &cobra.Command{
Use: "view",
Short: "View current values",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View current configuration values

cmd/config.go Outdated
var configurationViewCmd = &cobra.Command{
Use: "view",
Short: "View current values",
Long: "View current configuration",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View current configuration values

cmd/config.go Outdated
Short: "View current values",
Long: "View current configuration",
Example: ` # For viewing the current configuration
odo utils config view`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add a newline (see above). also change the two tabs to 3-spaces instead (it's messing up alignment when using odo utils --help

cmd/config.go Outdated
Use: "config",
Short: "Modifies configuration settings",
Long: `Modifies Odo specific configuration settings within the config file.
# Available Parameters:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks odd when doing --help

github.com/redhat-developer/odo  pr_589 ✔                                                                                                                                                                                                                                   3d  ⍉
▶ ./odo utils config --help
Modifies Odo specific configuration settings within the config file.
   # Available Parameters:
     UpdateNotification - Controls if an update notification is shown or not (true or false)

Usage:
  odo utils config [flags]
  odo utils config [command]

Aliases:
  config, configuration


Examples:
  # For viewing the current configuration
    odo utils config view
  # Set a configuration value
    odo utils config set UpdateNotification false


Available Commands:
  set         Set a value in odo config file
  view        View current values

Flags:
  -h, --help   help for config

Global Flags:
      --alsologtostderr                  log to standard error as well as files
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory
      --logtostderr                      log to standard error instead of files (default false)
      --skip-connection-check            Skip cluster check
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
  -v, --v Level                          log level for V logs
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

Use "odo utils config [command] --help" for more information about a command.

you should instead remove the # and remove the tabbing. Also add a newline between the 1st sentence and Available parameters.

@syamgk
Copy link
Member Author

syamgk commented Aug 28, 2018

@cdrage added a simple test it passed on CI yay!
https://travis-ci.org/redhat-developer/odo/jobs/421530938#L676

cmd/config.go Outdated
fmt.Println(err, ": unable to view configuration")
}
w := tabwriter.NewWriter(os.Stdout, 5, 2, 2, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "PARAMETER", "\t", "CURRENTVALUE")
Copy link
Contributor

@mik-dass mik-dass Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syamgk Please add a _ like CURRENT_VALUE for better readability

Copy link
Contributor

@surajnarwade surajnarwade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@syamgk syamgk force-pushed the odo-config branch 2 times, most recently from 2504238 to 8506be8 Compare August 30, 2018 13:05
@syamgk
Copy link
Member Author

syamgk commented Aug 30, 2018

squashed! now ready for merge :)

- add config command
- create a new field 'config' in odoconfig file
  for storing odo specific configurations
@cdrage
Copy link
Member

cdrage commented Sep 4, 2018

LGTM!

@cdrage cdrage merged commit 2bb2dca into redhat-developer:master Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants