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 possibility to override script values #138

Merged
merged 9 commits into from
Nov 2, 2020

Conversation

DnlLrssn
Copy link
Member

Checklist

Squash commit message

Add possibility to override script values

Info

https://github.com/qlik-oss/gopherciser/blob/enhancement/536-ScriptOverrides/docs/README.md#using-script-overrides

docs/README.md Outdated

`template` command flags:

* `-c`, `--config string`: (optional) Create the specified scenario setup file. Defaults to `template.json`.
* `-f`, `--force`: Overwrite existing scenario setup file.
* `-h`, `--help`: Show the help for the `template` command.

#### Using script overrides

Script overrides overrides a value pointed to by a path to its key. If the key doesn't exist in the script there will be a not found error, even if it's a valid value according to config.
Copy link
Contributor

Choose a reason for hiding this comment

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

A script override overrides a value..
or
Script overrides override values..

Copy link
Contributor

Choose a reason for hiding this comment

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

not-found-error? "not found"-error?

Copy link
Member Author

@DnlLrssn DnlLrssn Oct 29, 2020

Choose a reason for hiding this comment

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

If the key doesn't exist in the script there will an error, even if it's a valid value according to config.

?

return cfgJSON, overrides, errors.Errorf("malformed override: %s, should be in the form key.path=value", kvp)
}
path := helpers.DataPath(kvSplit[0])
rawOrig, err := path.Lookup(cfgJSON)
Copy link
Contributor

Choose a reason for hiding this comment

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

Still not entirely sure about this one 🤔 Also if the override is a json object, the individual keys won't be checked. I do understand it's a good thing to throw errors whenever possible, though, so removing it outright is not the best option either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not an easy one. My thinking, right or not, is that mistakes will more likely be done when writing the path, if an entire object is used it's at least more likely to be copy-pasted. My vote is on keeping the check, but agree not optimal, don't have a better solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I tend to agree if the choice is between keeping it and removing it outright.

@DnlLrssn
Copy link
Member Author

Should I add an option to read from file? Was thinking the format

key/to/path=value
key/to/path2=value2
key/to/pathN=valueN

then read line by line and execute as overrides.

@SeBBBe
Copy link
Contributor

SeBBBe commented Oct 29, 2020

That sounds like a good idea. I can foresee a situation where there are too many overrides in the scheduler to be able to pass via the command..

@SeBBBe
Copy link
Contributor

SeBBBe commented Oct 29, 2020

Either that or the ability to pass overrides over stdin

@DnlLrssn
Copy link
Member Author

Either that or the ability to pass overrides over stdin

Hmm true, will keep that in mind too

@atluq
Copy link
Contributor

atluq commented Oct 29, 2020

Should I add an option to read from file? Was thinking the format

key/to/path=value
key/to/path2=value2
key/to/pathN=valueN

then read line by line and execute as overrides.

It would also make sense for the file override to be ordinary json.

cmd/helpers.go Outdated Show resolved Hide resolved
@atluq
Copy link
Contributor

atluq commented Oct 29, 2020

There is actually a simple way of checking non-existing fields when unmarshalling json. This is not 100% related to this PR, but if we add this when unmarshalling the config in general we get some more safety when doing overrides.

@DnlLrssn
Copy link
Member Author

would not play nice with at least my way of work. I usually "comment" settings in actions by prefixing key with "_" or similar when I want temporarly want to use something else. Not sure how common that is though

@DnlLrssn
Copy link
Member Author

Also doesn't play well with the UnmarshalJSON interface which we use a lot of
golang/go#41144

@atluq
Copy link
Contributor

atluq commented Oct 29, 2020

would not play nice with at least my way of work. I usually "comment" settings in actions by prefixing key with "_" or similar when I want temporarly want to use something else. Not sure how common that is though

Yes, this is a con. There are comments in yaml 🙊

Also doesn't play well with the UnmarshalJSON interface which we use a lot of
golang/go#41144

Yes, looks like the the creation of decoder has to be scattered all over the place. There must be a way not to 🤔

@DnlLrssn DnlLrssn marked this pull request as ready for review October 30, 2020 10:49
@DnlLrssn
Copy link
Member Author

will keep current implementation of checking the path as a form of error handling, since other kinds seems to get messy. This can be re-visited at a later point when we see some adoption and usage and better can determine issues.

Copy link
Contributor

@SeBBBe SeBBBe left a comment

Choose a reason for hiding this comment

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

Looking good to me!

Copy link
Contributor

@atluq atluq left a comment

Choose a reason for hiding this comment

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

Looks good!

@DnlLrssn DnlLrssn merged commit f0b5d44 into master Nov 2, 2020
@DnlLrssn DnlLrssn deleted the enhancement/536-ScriptOverrides branch November 2, 2020 08:27
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.

5 participants