-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add prompt feature: select the patch/minor/major from prompt
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,63 @@ | ||
package gobump | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/manifoldco/promptui" | ||
"github.com/mattn/go-tty" | ||
) | ||
|
||
type promptResult int | ||
|
||
const ( | ||
promptResultNone promptResult = iota | ||
promptResultPatch | ||
promptResultMinor | ||
promptResultMajor | ||
) | ||
|
||
func promptTarget(currentVersion, target string) (promptResult, error) { | ||
tty, err := tty.Open() | ||
if err != nil { | ||
return promptResultNone, err | ||
} | ||
defer tty.Close() | ||
|
||
confs := []struct { | ||
name string | ||
config Config | ||
result promptResult | ||
}{ | ||
{"patch", Config{PatchDelta: 1}, promptResultPatch}, | ||
{"minor", Config{MinorDelta: 1}, promptResultMinor}, | ||
{"major", Config{MajorDelta: 1}, promptResultMajor}, | ||
} | ||
|
||
promptResults := make(map[int]promptResult) | ||
items := make([]string, len(confs)) | ||
|
||
for i, c := range confs { | ||
promptResults[i] = c.result | ||
newVersion, err := c.config.bumpedVersion(currentVersion) | ||
if err != nil { | ||
return promptResultNone, err | ||
} | ||
items[i] = fmt.Sprintf("%s (%s -> %s)", c.name, currentVersion, newVersion) | ||
} | ||
|
||
prompt := promptui.Select{ | ||
Label: "Bump up " + target, | ||
HideHelp: true, | ||
Items: items, | ||
Stdin: tty.Input(), | ||
Stdout: tty.Output(), | ||
} | ||
|
||
index, _, err := prompt.Run() | ||
|
||
if err != nil { | ||
return promptResultNone, err | ||
} | ||
|
||
return promptResults[index], nil | ||
} |