Skip to content

Commit 62c4c0e

Browse files
committed
renamed flags package
1 parent 6b58aad commit 62c4c0e

File tree

4 files changed

+30
-47
lines changed

4 files changed

+30
-47
lines changed

pkg/evgprompt/completer.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package evgprompt
33
import (
44
"chatton.com/evergreen-prompt/pkg/evergreen"
55
"chatton.com/evergreen-prompt/pkg/evergreen/client"
6-
"chatton.com/evergreen-prompt/pkg/util/flagutil"
6+
"chatton.com/evergreen-prompt/pkg/util/flags"
77
"github.com/c-bata/go-prompt"
88
"strings"
99
)
@@ -51,19 +51,10 @@ func (c *Completer) Complete(d prompt.Document) []prompt.Suggest {
5151
return nil
5252
}
5353

54-
//if getLastWord(d) == "--uncommitted" {
55-
// return nil
56-
//}
57-
5854
if strings.HasPrefix(d.TextBeforeCursor(), "patch") {
5955
return patchSuggestions(d)
6056
}
6157

62-
// don't display set-project if it has already been set.
63-
if strings.Contains(d.TextBeforeCursor(), "set-project") {
64-
return nil
65-
}
66-
6758
return prompt.FilterFuzzy([]prompt.Suggest{
6859
{
6960
Text: "patch",
@@ -77,23 +68,23 @@ func patchSuggestions(d prompt.Document) []prompt.Suggest {
7768
var suggestions []prompt.Suggest
7869

7970
// we only want to show suggestions when they have not yet been specified.
80-
if flagutil.GetTaskValue(d.TextBeforeCursor()) == "" {
71+
if flags.GetTaskValue(d.TextBeforeCursor()) == "" {
8172
suggestions = append(suggestions,
8273
prompt.Suggest{
8374
Text: "--task",
8475
Description: "Specify a task to run",
8576
})
8677
}
8778

88-
if flagutil.GetBuildVariantValue(d.TextBeforeCursor()) == "" {
79+
if flags.GetBuildVariantValue(d.TextBeforeCursor()) == "" {
8980
suggestions = append(suggestions,
9081
prompt.Suggest{
9182
Text: "--buildvariant",
9283
Description: "Specify a build variant",
9384
})
9485
}
9586

96-
if flagutil.GetDescriptionValue(d.TextBeforeCursor()) == "" {
87+
if flags.GetDescriptionValue(d.TextBeforeCursor()) == "" {
9788
if !strings.Contains(d.TextBeforeCursor(), "--description") {
9889
suggestions = append(suggestions,
9990
prompt.Suggest{
@@ -103,7 +94,7 @@ func patchSuggestions(d prompt.Document) []prompt.Suggest {
10394
}
10495
}
10596

106-
if flagutil.GetPriorityValue(d.TextBeforeCursor()) == "" {
97+
if flags.GetPriorityValue(d.TextBeforeCursor()) == "" {
10798
if !strings.Contains(d.TextBeforeCursor(), "--priority") {
10899
suggestions = append(suggestions,
109100
prompt.Suggest{
@@ -113,15 +104,15 @@ func patchSuggestions(d prompt.Document) []prompt.Suggest {
113104
}
114105
}
115106

116-
if !flagutil.HasSpecifiedUncommitted(d.TextBeforeCursor()) {
107+
if !flags.HasSpecifiedUncommitted(d.TextBeforeCursor()) {
117108
suggestions = append(suggestions,
118109
prompt.Suggest{
119110
Text: "--uncommitted",
120111
Description: "Include uncommitted changes",
121112
})
122113
}
123114

124-
if flagutil.GetProjectValue(d.TextBeforeCursor()) == "" {
115+
if flags.GetProjectValue(d.TextBeforeCursor()) == "" {
125116
suggestions = append(suggestions,
126117
prompt.Suggest{
127118
Text: "--project",
@@ -153,9 +144,9 @@ func (c *Completer) getTaskSuggestions(d prompt.Document) []prompt.Suggest {
153144

154145
// if we are getting the task and the buildvariant already specified, we need to show
155146
// only the tasks that contain this build varient otherwise we can show all the tasks.
156-
buildvariantValue := flagutil.GetBuildVariantValue(d.TextBeforeCursor())
147+
buildvariantValue := flags.GetBuildVariantValue(d.TextBeforeCursor())
157148

158-
if buildvariantValue == "" {
149+
if buildvariantValue == "" {
159150
for _, t := range c.config.Tasks {
160151
suggestions = append(suggestions, prompt.Suggest{
161152
Text: t.Name,
@@ -182,7 +173,7 @@ func (c *Completer) getBuildVariantSuggestions(d prompt.Document) []prompt.Sugge
182173

183174
// if we are getting the build variant and the task is already specified, we need to show
184175
// only the build variants that contain this task, otherwise we can show all the buildvariants.
185-
taskValue := flagutil.GetTaskValue(d.TextBeforeCursor())
176+
taskValue := flags.GetTaskValue(d.TextBeforeCursor())
186177

187178
if taskValue == "" {
188179
for _, bv := range c.config.BuildVariants {

pkg/evgprompt/executor.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package evgprompt
33
import (
44
"chatton.com/evergreen-prompt/pkg/evergreen/client"
55
"chatton.com/evergreen-prompt/pkg/evergreen/patch"
6-
"chatton.com/evergreen-prompt/pkg/util/flagutil"
6+
"chatton.com/evergreen-prompt/pkg/util/flags"
77
"fmt"
88
"os"
99
"os/exec"
@@ -28,43 +28,35 @@ func (e *Executor) Execute(in string) {
2828
os.Exit(0)
2929
}
3030

31-
//if strings.HasPrefix(in, "set-project") {
32-
// split := strings.Split(in, " ")
33-
// project := split[1]
34-
// fmt.Println("setting active project to: " + project)
35-
// e.client.ActiveProject = project
36-
// return
37-
//}
38-
3931
if strings.HasPrefix(in, "patch") {
4032

4133
args := []string{
4234
"patch", "-f", "-y",
4335
}
4436

45-
if project := flagutil.GetProjectValue(in); project != "" {
37+
if project := flags.GetProjectValue(in); project != "" {
4638
args = append(args, "-p", project)
4739
}
4840

49-
if flagutil.HasSpecifiedUncommitted(in) {
41+
if flags.HasSpecifiedUncommitted(in) {
5042
args = append(args, "-u")
5143
}
5244

53-
task := flagutil.GetTaskValue(in)
45+
task := flags.GetTaskValue(in)
5446
if task == "" {
5547
fmt.Println("Task must be specified!")
5648
}
5749

5850
args = append(args, "-t", task)
5951

60-
buildvariant := flagutil.GetBuildVariantValue(in)
52+
buildvariant := flags.GetBuildVariantValue(in)
6153
if buildvariant == "" {
6254
fmt.Println("Buildvariant must be specified!")
6355
}
6456

6557
args = append(args, "-v", buildvariant)
6658

67-
description := flagutil.GetDescriptionValue(in)
59+
description := flags.GetDescriptionValue(in)
6860
if description == "" {
6961
description = "evergreen-prompt task"
7062
}
@@ -80,7 +72,7 @@ func (e *Executor) Execute(in string) {
8072

8173
id := getPatchIdFromCliOutput(string(out))
8274

83-
if priority := flagutil.GetPriorityValue(in); priority != "" {
75+
if priority := flags.GetPriorityValue(in); priority != "" {
8476
// set priority of patch
8577
_, err := e.client.PatchPatch(id, patch.Body{Priority: 10})
8678
if err != nil {
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package flagutil
1+
package flags
22

33
import (
44
"regexp"
@@ -16,50 +16,50 @@ func init() {
1616
}
1717

1818
func GetBuildVariantValue(s string) string {
19-
if bv, ok := ExtractFlags(s, "patch")["--buildvariant"]; ok {
19+
if bv, ok := extractFlags(s, "patch")["--buildvariant"]; ok {
2020
return bv
2121
}
2222
return ""
2323
}
2424

2525
func GetTaskValue(s string) string {
26-
if task, ok := ExtractFlags(s, "patch")["--task"]; ok {
26+
if task, ok := extractFlags(s, "patch")["--task"]; ok {
2727
return task
2828
}
2929
return ""
3030
}
3131

3232
func GetDescriptionValue(s string) string {
33-
if description, ok := ExtractFlags(s, "patch")["--description"]; ok {
33+
if description, ok := extractFlags(s, "patch")["--description"]; ok {
3434
return description
3535
}
3636
return ""
3737
}
3838

3939
func GetPriorityValue(s string) string {
40-
if priority, ok := ExtractFlags(s, "patch")["--priority"]; ok {
40+
if priority, ok := extractFlags(s, "patch")["--priority"]; ok {
4141
return priority
4242
}
4343
return ""
4444
}
4545

4646
func GetProjectValue(s string) string {
47-
if project, ok := ExtractFlags(s, "patch")["--project"]; ok {
47+
if project, ok := extractFlags(s, "patch")["--project"]; ok {
4848
return project
4949
}
5050
return ""
5151
}
5252

5353
func HasSpecifiedUncommitted(s string) bool {
54-
_, ok := ExtractFlags(s, "patch")["--uncommitted"]
54+
_, ok := extractFlags(s, "patch")["--uncommitted"]
5555
return ok
5656
}
5757

58-
// ExtractFlags converts a string with the given prefix into a map[string]string
58+
// extractFlags converts a string with the given prefix into a map[string]string
5959
// with the keys as the flags and the provided values as the map values.
6060
// if the flag does not require a value, an empty string will be set as the value
6161
// in the map/
62-
func ExtractFlags(s, prefix string) map[string]string {
62+
func extractFlags(s, prefix string) map[string]string {
6363
flags := map[string]string{}
6464

6565
flagsOnly := strings.TrimLeft(s, prefix)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package flagutil
1+
package flags
22

33
import (
44
"github.com/go-playground/assert/v2"
@@ -39,15 +39,15 @@ func TestExtractFlags(t *testing.T) {
3939

4040
t.Run("Test even number of values", func(t *testing.T) {
4141
input := "patch --task this_is_my_task --buildvariant this_is_my_bv"
42-
flags := ExtractFlags(input, "patch")
42+
flags := extractFlags(input, "patch")
4343

4444
assert.Equal(t, "this_is_my_task", flags["--task"])
4545
assert.Equal(t, "this_is_my_bv", flags["--buildvariant"])
4646
})
4747

4848
t.Run("Test with flags that have no value as last item", func(t *testing.T) {
4949
input := "patch --task this_is_my_task --buildvariant this_is_my_bv --uncommited"
50-
flags := ExtractFlags(input, "patch")
50+
flags := extractFlags(input, "patch")
5151

5252
assert.Equal(t, "this_is_my_task", flags["--task"])
5353
assert.Equal(t, "this_is_my_bv", flags["--buildvariant"])
@@ -56,7 +56,7 @@ func TestExtractFlags(t *testing.T) {
5656

5757
t.Run("Test with flags that have no value as middle item", func(t *testing.T) {
5858
input := "patch --task this_is_my_task --buildvariant this_is_my_bv --uncommited --priority 100"
59-
flags := ExtractFlags(input, "patch")
59+
flags := extractFlags(input, "patch")
6060

6161
assert.Equal(t, "this_is_my_task", flags["--task"])
6262
assert.Equal(t, "this_is_my_bv", flags["--buildvariant"])

0 commit comments

Comments
 (0)