This repository was archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 329
core/cli: Update profile set to use defaults on init only #3854
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
68e6028
core/cli: Add string ptr to flag types
demophoon 30fb1e0
core/cli: Update runner profile command for proper upsert
demophoon 622ed32
core/cli: Set target runner to any when initializing profile
demophoon 4c38c78
Add changelog
demophoon 223b658
docs: update website with new flag
demophoon cebe713
Update warning message when both labels and any specified
demophoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ```release-note:improvement | ||
| cli: Setting configurations in a runner profile no longer resets unspecified configuration | ||
| ``` | ||
|
|
||
| ```release-note:improvement | ||
| cli: A new `-runner-target-any` flag has been added to runner profile set to allow users to specify targeting any runner. | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package flag | ||
|
|
||
| import ( | ||
| "github.com/posener/complete" | ||
| ) | ||
|
|
||
| // -- StringPtrVar and stringValue | ||
| type StringPtrVar struct { | ||
| Name string | ||
| Aliases []string | ||
| Usage string | ||
| Default string | ||
| Hidden bool | ||
| EnvVar string | ||
| Target **string | ||
| Completion complete.Predictor | ||
| SetHook func(val string) | ||
| } | ||
|
|
||
| func (f *Set) StringPtrVar(i *StringPtrVar) { | ||
| f.VarFlag(&VarFlag{ | ||
| Name: i.Name, | ||
| Aliases: i.Aliases, | ||
| Default: i.Default, | ||
| Usage: i.Usage, | ||
| EnvVar: i.EnvVar, | ||
| Value: newStringPtr(i, i.Target, i.Hidden), | ||
| Completion: i.Completion, | ||
| }) | ||
| } | ||
|
|
||
| type stringPtrValue struct { | ||
| v *StringPtrVar | ||
| hidden bool | ||
| target **string | ||
| } | ||
|
|
||
| func newStringPtr(v *StringPtrVar, target **string, hidden bool) *stringPtrValue { | ||
| return &stringPtrValue{ | ||
| v: v, | ||
| hidden: hidden, | ||
| target: target, | ||
| } | ||
| } | ||
|
|
||
| func (s *stringPtrValue) Set(val string) error { | ||
| *s.target = &val | ||
|
|
||
| if s.v.SetHook != nil { | ||
| s.v.SetHook(val) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (s *stringPtrValue) String() string { | ||
| if *s.target != nil { | ||
| return **s.target | ||
| } | ||
| return s.v.Default | ||
| } | ||
|
|
||
| func (s *stringPtrValue) Get() interface{} { return s.target } | ||
| func (s *stringPtrValue) Example() string { return "string" } | ||
| func (s *stringPtrValue) Hidden() bool { return s.hidden } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package flag | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestStringPtrVar(t *testing.T) { | ||
| cases := map[string]struct { | ||
| input *string | ||
| expected *string | ||
| omitValue bool // e.g. -poll instead of -poll=true | ||
| shouldErr bool | ||
| }{ | ||
| "omitted": { | ||
| expected: nil, | ||
| }, | ||
| // specifying -flag without a value should fail | ||
| "no value set": { | ||
| omitValue: true, | ||
| shouldErr: true, | ||
| }, | ||
| "value passed in": { | ||
| input: strPtr("blammo"), | ||
| expected: strPtr("blammo"), | ||
| }, | ||
| // empty is equivilant to a user supplying -flag="", and not a scenario | ||
| // where the flag is simply omittied. | ||
| "empty string as input": { | ||
| input: strPtr(""), | ||
| expected: strPtr(""), | ||
| }, | ||
| } | ||
|
|
||
| for name, c := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| var valA *string | ||
| var valB string | ||
| sets := NewSets() | ||
| { | ||
| set := sets.NewSet("A") | ||
| set.StringPtrVar(&StringPtrVar{ | ||
| Name: "a", | ||
| Target: &valA, | ||
| }) | ||
| } | ||
| { | ||
| // borrowed from string_slice_test, just to have another input | ||
| set := sets.NewSet("B") | ||
| set.StringVar(&StringVar{ | ||
| Name: "b", | ||
| Target: &valB, | ||
| }) | ||
| } | ||
|
|
||
| var err error | ||
| inputs := []string{"-b=somevalueB"} | ||
| if c.input != nil { | ||
| inputs = append(inputs, "-a="+*c.input) | ||
| } | ||
| if c.omitValue == true { | ||
| inputs = append(inputs, "-a") | ||
| } | ||
| err = sets.Parse(inputs) | ||
| if c.shouldErr { | ||
| assert.Error(t, err) | ||
| } else { | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| assert.Equal(t, c.expected, valA) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,5 +44,6 @@ lifecycle operation. | |
| - `-default` - Indicates that this remote runner profile should be the default for any project that doesn't otherwise specify its own remote runner. | ||
| - `-target-runner-id=<string>` - ID of the runner to target for this remote runner profile. | ||
| - `-target-runner-label=<key=value>` - Labels on the runner to target for this remote runner profile. e.g. `-target-runner-label=k=v`. Can be specified multiple times. | ||
| - `-target-runner-any` - Set profile to target any available runner. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very good catch |
||
|
|
||
| @include "commands/runner-profile-set_more.mdx" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.