[OCONF-166] coconut conf import command#71
Conversation
…ub.com:AliceO2Group/Control into feature/OCONF-166-coconut-import-command
…/OCONF-166-coconut-import-command
|
Fixes please: import command
show command
Suggestions:
|
| coconut conf import <component/entry> <file_path> --format=json | ||
| coconut conf import <component/entry> <file_path>.json | ||
| `, | ||
| Short: "Import a configuration file for the component and entry specified", |
There was a problem hiding this comment.
Import a configuration file for the specified component and entry
| Use: "import <component> <entry> <file_path>", | ||
| Aliases: []string{"i", "imp"}, | ||
| Example: `coconut conf import <component> <entry> <file_path> | ||
| coconut conf import <component/entry> <file_path> |
There was a problem hiding this comment.
Minor nitpick: I'd put <component>/<entry> instead of <component/entry> as component and entry are the variables here, which we compose in one way or another.
| coconut conf import <component/entry> <file_path>.json | ||
| `, | ||
| Short: "Import a configuration file for the component and entry specified", | ||
| Long: `The configuration import command will generate a timestamp and save |
| `, | ||
| Short: "Import a configuration file for the component and entry specified", | ||
| Long: `The configuration import command will generate a timestamp and save | ||
| the configuration file under the component/entry/timestamp path in Consul. Default |
There was a problem hiding this comment.
... save the configuration file to Consul under the path <component>/<entry>/<timestamp>.
| Short: "Import a configuration file for the component and entry specified", | ||
| Long: `The configuration import command will generate a timestamp and save | ||
| the configuration file under the component/entry/timestamp path in Consul. Default | ||
| accepted file extensions are JSON, YAML, TOML, INI`, |
There was a problem hiding this comment.
s/Default accepted file extensions are/Supported configuration file types are JSON, YAML, TOML and INI, and their file extensions are recognized automatically./
| func init() { | ||
| configurationCmd.AddCommand(configurationImportCmd) | ||
| configurationImportCmd.Flags().BoolP("new-component", "n", false, "used to add a new component") | ||
| configurationImportCmd.Flags().StringP("format", "f", "", "used to specify a different extension file than default (JSON, YAML, INI, TOML)") |
There was a problem hiding this comment.
force a specific configuration file type, overriding any file extension
|
|
||
| func init() { | ||
| configurationCmd.AddCommand(configurationImportCmd) | ||
| configurationImportCmd.Flags().BoolP("new-component", "n", false, "used to add a new component") |
There was a problem hiding this comment.
create a new configuration component while importing entry
| for key, _ := range components { | ||
| componentMsg += "\n-" + key | ||
| } | ||
| return errors.New(fmt.Sprintf("Component `" + component + "` does not exist. " + |
There was a problem hiding this comment.
Let's not use backticks here, either color or nothing. The backticks can potentially make sense in Cobra command doc strings because those are exported as Markdown, but not in error messages.
|
|
||
| func isFileExtensionValid(extension string) bool{ | ||
| extension = strings.ToUpper(extension) | ||
| return extension == "JSON" || extension == "YAML" || extension == "INI" || extension == "TOML" |
There was a problem hiding this comment.
Let's also allow .yml just in case. Visible strings should not be changed, just the logic to approve the file extension.
| err = errors.New(fmt.Sprintf("Requested component name cannot contain character `/` or `@`")) | ||
| return err, invalidArgs | ||
| if !isInputSingleValidWord(args[0]) { | ||
| return errors.New(fmt.Sprintf(invalidArgsErrMsg)), invalidArgs |
There was a problem hiding this comment.
This may simply be errors.New(invalidArgsErrMsg). https://golang.org/pkg/errors/#New
fmt.Sprintf() is not necessary if you don't have some fancy arguments you want to handle.
There was a problem hiding this comment.
Did not know. Thank you 👍
There was a problem hiding this comment.
There's also fmt.Errorf that combines the two for when you do need to handle fancy arguments ;)
| componentsSet[componentsFullName] = componentTimestamp | ||
| } | ||
| entryExists := false | ||
| if useNewComponent { |
There was a problem hiding this comment.
Not anymore. I negated it
|
|
||
| var maxTimeStamp uint64 | ||
| for _, key := range keys { | ||
| componentTimestamp, err := strconv.ParseUint(strings.TrimPrefix(key, keyPrefix + "/"), 10, 64) |
There was a problem hiding this comment.
I imagine this is done on purpose here, but this leads to variable shadowing, which could in turn lead to errors. A very good explanation can be found here.
There was a problem hiding this comment.
In this case I am not interested in stopping the whole command if one of the timestamps is bad. Thus, I am adding it to the list of elements only if it is a valid one. So even if the timestamp is not correct, it will be ignored.
The error that I am interested here is the one with emptyData
| coconut conf import <component> <entry> <file_path> --new-component | ||
| coconut conf import <component> <entry> <file_path> --format=json | ||
| coconut conf import <component> <entry> <file_path>.json |
There was a problem hiding this comment.
We seem to be missing the <component>/<entry> bits.
There was a problem hiding this comment.
They are not missing as the requirement was to have exactly 3 arguments:
coconut conf import <component name> <entry name> <file path> [options]
Would you like that option added?
There was a problem hiding this comment.
I see, so coconut conf import <component/entry> <file_path>.json never worked even when it was documented?
There was a problem hiding this comment.
No. It was a mistake when documentation was added and on second look of the requirements it was then removed.
If we wish to support that we can added so that we are in line with the
coconut conf show command
There was a problem hiding this comment.
Yes, that would be splendid, and also the final thing before we merge.
There was a problem hiding this comment.
The feature implementation looks good, could you please just add back the relevant documentation lines for the <component>/<entry> syntax? Once this is done we can merge.
| nonZero = iota | ||
| invalidArgs = iota // Provided args by the user are invalid | ||
| invalidArgsErrMsg = "Component and Entry names cannot contain `/ or `@`" | ||
| invalidArgsErrMsg = "component and Entry names cannot contain `/ or `@`" |
| } | ||
| fullKey := red(component) + "/" + blue(entry) + "@" + strconv.FormatInt(timestamp, 10) | ||
| userMsg += "The following configuration key has been added: " + fullKey | ||
| userMsg += "Configuration created: " + fullKey |
There was a problem hiding this comment.
I know we discussed this at length trying to find the best wording and we settled on this, but after additional thought I realized that:
- this string is the only one that's always printed (the ones for new entry and component aren't)
- this string is the last (and sometimes only) line of output in response to a
coconut conf importcommand.
Therefore I propose the following:
userMsg += "Configuration imported: " + fullKey
No description provided.