Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .golangci.bck.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
const schemaFile = "schema.graphql"

if _, err := os.Stat(schemaFile); errors.Is(err, os.ErrNotExist) {
var headers = http.Header{
headers := http.Header{
"Authorization": []string{fmt.Sprintf("Bearer %s", os.Getenv("BUILDKITE_GRAPHQL_TOKEN"))},
}

Expand Down
61 changes: 45 additions & 16 deletions pkg/cmd/configure/add/add.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package add

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
"syscall"

"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/charmbracelet/huh"
"github.com/spf13/cobra"
"golang.org/x/term"
)

func NewCmdAdd(f *factory.Factory) *cobra.Command {
Expand All @@ -30,25 +35,49 @@ func ConfigureWithCredentials(f *factory.Factory, org, token string) error {
}

func ConfigureRun(f *factory.Factory) error {
var org, token string
nonEmpty := func(s string) error {
if len(s) == 0 {
return errors.New("value cannot be empty")
}
return nil
// Get organization slug
org, err := promptForInput("Organization slug: ", false)
if err != nil {
return err
}
if org == "" {
return errors.New("organization slug cannot be empty")
}
form := huh.NewForm(
huh.NewGroup(
huh.NewInput().Title("Organization slug: ").Value(&org).Validate(nonEmpty).Inline(true).Prompt(""),
),
huh.NewGroup(
huh.NewInput().Title("API Token: ").Value(&token).EchoMode(huh.EchoModePassword).Validate(nonEmpty).Inline(true).Prompt(""),
),
).WithTheme(huh.ThemeBase16())
err := form.Run()

// Get API token with password input (no echo)
token, err := promptForInput("API Token: ", true)
if err != nil {
return err
}
if token == "" {
return errors.New("API token cannot be empty")
}

fmt.Println("API token set for organization:", org)

return ConfigureWithCredentials(f, org, token)
}

// promptForInput handles terminal input with optional password masking
func promptForInput(prompt string, isPassword bool) (string, error) {
fmt.Print(prompt)

if isPassword {
// Use term.ReadPassword for secure password input
passwordBytes, err := term.ReadPassword(int(syscall.Stdin))
fmt.Println() // Add a newline after password input
if err != nil {
return "", err
}
return string(passwordBytes), nil
} else {
// Use standard input for regular text
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
return "", err
}
// Trim whitespace and newlines
return strings.TrimSpace(input), nil
}
}