Skip to content

Commit

Permalink
Downgrade go-prompt due to c-bata/go-prompt#233
Browse files Browse the repository at this point in the history
  • Loading branch information
imander committed Oct 4, 2021
1 parent 299bd81 commit b1abcfc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module jenkins-cli
go 1.17

require (
github.com/c-bata/go-prompt v0.2.6
github.com/c-bata/go-prompt v0.2.5
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
)
Expand All @@ -13,7 +13,7 @@ require (
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/pkg/term v1.1.0 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI=
github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY=
github.com/c-bata/go-prompt v0.2.5 h1:3zg6PecEywxNn0xiqcXHD96fkbxghD+gdB2tbsYfl+Y=
github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -14,8 +14,8 @@ github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw=
github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down
32 changes: 9 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ var (
commands = []prompt.Suggest{
{Text: "dump-creds", Description: "Print all stored credentials to the console"},
{Text: "login", Description: "Log into a Jenkins host"},
{Text: "exit", Description: "Exit the cli"},
}
aliases = map[string]string{
"l": "ls",
Expand Down Expand Up @@ -106,7 +105,7 @@ func login() {
}

func loginPrompt() error {
u := getInput(urlPrompt(), jenkins.URL)
u := getInput("Jenkins URL", jenkins.URL)
ur, err := url.Parse(u)
if err != nil {
return errors.Wrap(err, "Invalid URL")
Expand All @@ -115,16 +114,21 @@ func loginPrompt() error {
return errors.New("URL must have http/https scheme")
}
jenkins.URL = ur.String()
jenkins.User = getInput(userPrompt(), jenkins.User)
jenkins.User = getInput("Jenkins User", jenkins.User)
jenkins.Password = getPassword()
return nil
}

func getInput(msg, def string) string {
func getInput(msg, current string) string {
if current != "" {
msg = msg + fmt.Sprintf(" [%s]: ", current)
} else {
msg += ": "
}
c := func(in prompt.Document) []prompt.Suggest { return nil }
in := prompt.Input(msg, c)
if in == "" {
return def
return current
}
return in
}
Expand All @@ -143,22 +147,6 @@ func getPassword() string {
return p
}

func urlPrompt() string {
p := "Jenkins URL"
if jenkins.URL != "" {
return p + fmt.Sprintf(" [%s]: ", jenkins.URL)
}
return p + ": "
}

func userPrompt() string {
p := "Jenkins User"
if jenkins.User != "" {
return p + fmt.Sprintf(" [%s]: ", jenkins.User)
}
return p + ": "
}

func executor(cmd string) {
if changeDir(cmd) {
return
Expand All @@ -169,8 +157,6 @@ func executor(cmd string) {
return
case "dump-creds":
scriptConsole(commandPayload(credsScript))
case "exit":
os.Exit(0)
case "login":
login()
default:
Expand Down

0 comments on commit b1abcfc

Please sign in to comment.