-
Notifications
You must be signed in to change notification settings - Fork 244
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
Conversation
928fe24
to
ce89cb3
Compare
58e04d7
to
37228d3
Compare
@syamgk , there's a problem
|
good catch @surajnarwade |
cmd/config.go
Outdated
var configurationCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "Modifying configuration settings", | ||
Long: `Performs edits on configuration settings on config file.`, |
There was a problem hiding this comment.
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.
pkg/config/config.go
Outdated
configFileName = "odo" | ||
) | ||
|
||
// ConfigurationInfo holds all odo specific configurations | ||
type ConfigurationInfo struct { |
There was a problem hiding this comment.
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.
pkg/config/config.go
Outdated
@@ -16,6 +16,11 @@ const ( | |||
configFileName = "odo" | |||
) | |||
|
|||
// ConfigurationInfo holds all odo specific configurations | |||
type ConfigurationInfo struct { | |||
UpdateNotification bool `json:"updatenotification"` |
There was a problem hiding this comment.
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.
pkg/config/config.go
Outdated
@@ -112,6 +120,46 @@ func (c *ConfigInfo) writeToFile() error { | |||
return nil | |||
} | |||
|
|||
// SetConfiguration Set Odo configurations | |||
func SetConfiguration(component string, value bool) error { |
There was a problem hiding this comment.
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
pkg/config/config.go
Outdated
} | ||
|
||
// GetupdateNotificationStatus returns the value of UpdateNotification config | ||
func GetupdateNotificationStatus() bool { |
There was a problem hiding this comment.
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.
pkg/config/config.go
Outdated
|
||
// Getconfiguration get odo configurations | ||
func GetConfiguration() error { | ||
cfg, err := New() |
There was a problem hiding this comment.
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] { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.`, |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove name
pkg/config/config.go
Outdated
@@ -112,6 +120,46 @@ func (c *ConfigInfo) writeToFile() error { | |||
return nil | |||
} | |||
|
|||
// SetConfiguration Set Odo configurations |
There was a problem hiding this comment.
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
pkg/config/config.go
Outdated
cfg.OdoConfigurations.UpdateNotification = value | ||
err = cfg.writeToFile() | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to set updatenotification to %t ", value) |
There was a problem hiding this comment.
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
pkg/config/config.go
Outdated
func SetConfiguration(component string, value bool) error { | ||
cfg, err := New() | ||
if err != nil { | ||
return errors.Wrap(err, "unable to modify configuration") |
There was a problem hiding this comment.
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?
pkg/config/config.go
Outdated
return nil | ||
} | ||
|
||
// Getconfiguration get odo configurations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More descriptive configuration :)
9b40e33
to
33dcd32
Compare
096374f
to
d4df9d5
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"} |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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
Check
I think we should follow this for
|
@surajnarwade Agreed @syamgk can you please rebase this and |
There was a problem hiding this 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 ;-)
@surajnarwade changed @kadel rebased the PR If everything looks good I can squash the commit and update the commit message |
There was a problem hiding this 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`, |
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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`, |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
@cdrage added a simple test it passed on CI yay! |
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
2504238
to
8506be8
Compare
squashed! now ready for merge :) |
- add config command - create a new field 'config' in odoconfig file for storing odo specific configurations
LGTM! |
for storing odo specific configurations