Skip to content

Commit

Permalink
fix(#103): cannot pass jira token type selection on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-5 committed Jan 20, 2024
1 parent bb359e5 commit 042b3ff
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/sahilm/fuzzy v0.1.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.7.1
github.com/tcnksm/go-input v0.0.0-20180404061846-548a7d7a8ee8
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -27,7 +26,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tcnksm/go-input v0.0.0-20180404061846-548a7d7a8ee8 h1:RB0v+/pc8oMzPsN97aZYEwNuJ6ouRJ2uhjxemJ9zvrY=
github.com/tcnksm/go-input v0.0.0-20180404061846-548a7d7a8ee8/go.mod h1:IlWNj9v/13q7xFbaK4mbyzMNwrZLaWSHx/aibKIZuIg=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
44 changes: 29 additions & 15 deletions internal/fjira/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/mk-5/fjira/internal/jira"
"github.com/mk-5/fjira/internal/ui"
"github.com/mk-5/fjira/internal/workspaces"
goinput "github.com/tcnksm/go-input"
"io"
"os"
"regexp"
"strconv"
"strings"
)

Expand Down Expand Up @@ -154,23 +154,37 @@ func readFromUserInputAndStore(input io.Reader, workspace string, existingSettin
if err != nil {
return nil, err
}
tokenTypeOptions := []string{string(jira.ApiToken), string(jira.PersonalToken)}
fmt.Print(color.HiYellowString(ui.MessageQuestionMark))
u := &goinput.UI{
Writer: os.Stdout,
Reader: input,
}
tokenType := jira.ApiToken
fmt.Print(ui.MessageEnterJiraTokenType)
if existingSettings != nil && existingSettings.JiraTokenType != "" {
tokenType = existingSettings.JiraTokenType
fmt.Print(color.BlueString("[%s] ", existingSettings.JiraTokenType))
}
tokenTypeOptions := []string{string(jira.ApiToken), string(jira.PersonalToken)}
tokenTypeStr, err := u.Select(ui.MessageEnterJiraTokenType, tokenTypeOptions, &goinput.Options{
Default: string(tokenType),
Required: true,
Loop: true,
})
if err != nil {
return nil, err
fmt.Println("")
fmt.Println("1. api token")
fmt.Println("2. personal token")
fmt.Println("")
var tokenOption int
for {
fmt.Print(ui.MessageEnterJiraTokenNumber)
tokenOptionStr, err := reader.ReadString('\n')
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return nil, err
}
tokenOption, err = strconv.Atoi(strings.TrimSpace(tokenOptionStr))
if err == nil && tokenOption > 0 && tokenOption <= len(tokenTypeOptions) {
break
}
fmt.Println("")
}
var tokenTypeStr string
if tokenOption == 0 && existingSettings != nil && existingSettings.JiraTokenType != "" {
tokenTypeStr = string(existingSettings.JiraTokenType)
} else {
tokenTypeStr = tokenTypeOptions[tokenOption-1]
}
settings := &workspaces.WorkspaceSettings{
JiraToken: strings.TrimSpace(token),
Expand Down
1 change: 1 addition & 0 deletions internal/ui/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
MessageQuestionMark = "? "
MessageEnterJiraApiToken = "Jira Api Token: "
MessageEnterJiraTokenType = "Jira Token Type: "
MessageEnterJiraTokenNumber = "Enter a number (Default is 1): "
MessageProjectLabel = "Project: "
MessageIssueLabel = "Issue: "
MessageLabelStatus = "Status: "
Expand Down

0 comments on commit 042b3ff

Please sign in to comment.