Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(cli): provide parameter values via command line#8898

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 34 commits intomainfrom8782-build-option
Aug 9, 2023

Conversation

@mtojek
Copy link
Member

@mtojekmtojek commentedAug 4, 2023
edited
Loading

Fixes:#8782

This PR refactors the parameter-resolving logic in Coder CLI in terms of consistency and cleaner code. Additionally, it enables passing parameter values via command line flags (--build-option and--parameter).

Note:

The business logic is updated. I may need to cover the new flags with tests, but the assumption is that existing CLI tests should not change unless there are new issues discovered.

@mtojekmtojek self-assigned thisAug 4, 2023
@mtojekmtojek changed the titlefeat(cli): provide parameter values via CLIfeat(cli): provide parameter values via command lineAug 4, 2023
@mtojekmtojek marked this pull request as ready for reviewAugust 8, 2023 13:27
@mtojekmtojek requested a review frommafredriAugust 8, 2023 13:31
Copy link
Member

@mafredrimafredri 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 👍. A few small suggestions and I'm thinking it might be good to have a bit more test coverage of the precedence of parameter/build values. I.e. when they're coming from previous builds, files and flags (and different combinations of). I don't see that as a reason to delay this PR though.

fori,r:=rangeresolved {
ifr.Name==name {
resolved[i].Value=value
goto done
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: We could label the loop instead and usecontinue Loop. Continue/break have a simpler flow and are usually considered more idiomatic Go.

(Same with other loops.)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Are you thinking about this form:

next:forname,value:=rangepr.richParametersFile {fori,r:=rangeresolved {ifr.Name==name {resolved[i].Value=valuecontinue next}}resolved=append(resolved, codersdk.WorkspaceBuildParameter{Name:name,Value:value,})}

If so, then it will be a bit different logic - iterate overpr.richParametersFile again and again.

Alternatively, I can add break/if, but withgoto the code is shorter/simpler.

Copy link
Member

@mafredrimafredriAug 9, 2023
edited
Loading

Choose a reason for hiding this comment

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

I think there's a misunderstanding around how loop labels work. This is kind of like tagging a loop so thatcontinue knows where to go. See here (only one iteration through the range is performed):https://go.dev/play/p/oAbzFLuh8O5

The reason I saycontinue/break [Label] is simpler, is that they don't break control flow, whereasgoto does and can go anywhere in the function.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

returnxerrors.Errorf("parameter %q is not present in the template",r.Name)
}

iftvp.Ephemeral&&!pr.promptBuildOptions&&len(pr.buildOptions)==0 {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we check len 0 here? Wouldn't it be possible for some build options to be provided but not this one? Should are check the contents instead?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This condition only applies to ephemeral/one-time build parameters, hencetvp.Ephemeral.!pr.promptBuildOptions means that the user didn't use the flag--build-options to input manually values for next build options, andlen(pr.buildOptions) == 0 means that they didn't provide them via--build-option key=value.

Copy link
Member

Choose a reason for hiding this comment

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

I understand the reasoning for the other checks, however my thinking is that, say there are two ephemeral values. The user providers onlyone of them via--build-option. Thenlen(pr.buildOptions) == 1 even though currenttvp wasn't provided. Does that make sense?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@mtojek
Copy link
MemberAuthor

I'm thinking it might be good to have a bit more test coverage of the precedence of parameter/build values. I.e. when they're coming from previous builds, files and flags (and different combinations of)

I admit that I don't want to blow up CLI with an excessive number of test cases. Full coverage would require a matrix<create/update/start/restart>:<build-option>:<parameter-flag>:<parameter-file>.

@mtojek
Copy link
MemberAuthor

I'm going to merge this PR, and apply fixes in follow ups if necessary. In the worst case, this PR be reverted entirely as it just modifies CLI.

@mtojekmtojek merged commit0d382d1 intomainAug 9, 2023
@mtojekmtojek deleted the 8782-build-option branchAugust 9, 2023 11:00
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 9, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@mafredrimafredrimafredri approved these changes

Assignees

@mtojekmtojek

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Specify one-time parameters on CLI command line

3 participants

@mtojek@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp