Skip to content

Commit

Permalink
Move console form to ui/console/form package
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić authored and imiric committed Dec 20, 2022
1 parent 8f81858 commit 6ade203
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
12 changes: 6 additions & 6 deletions cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"go.k6.io/k6/cloudapi"
"go.k6.io/k6/lib/consts"
"go.k6.io/k6/ui"
"go.k6.io/k6/ui/console/form"
)

//nolint:funlen,gocognit
Expand Down Expand Up @@ -70,13 +70,13 @@ This will set the default token used when just "k6 run -o cloud" is passed.`,
case token.Valid:
newCloudConf.Token = token
default:
form := ui.Form{
Fields: []ui.Field{
ui.StringField{
f := form.Form{
Fields: []form.Field{
form.StringField{
Key: "Email",
Label: "Email",
},
ui.PasswordField{
form.PasswordField{
Key: "Password",
Label: "Password",
},
Expand All @@ -86,7 +86,7 @@ This will set the default token used when just "k6 run -o cloud" is passed.`,
globalState.logger.Warn("Stdin is not a terminal, falling back to plain text input")
}
var vals map[string]string
vals, err = form.Run(globalState.console.Stdin, globalState.console.Stdout)
vals, err = f.Run(globalState.console.Stdin, globalState.console.Stdout)
if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/login_influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gopkg.in/guregu/null.v3"

"go.k6.io/k6/output/influxdb"
"go.k6.io/k6/ui"
"go.k6.io/k6/ui/console/form"
)

//nolint:funlen
Expand Down Expand Up @@ -46,24 +46,24 @@ This will set the default server used when just "-o influxdb" is passed.`,
conf = conf.Apply(urlConf)
}

form := ui.Form{
Fields: []ui.Field{
ui.StringField{
f := form.Form{
Fields: []form.Field{
form.StringField{
Key: "Addr",
Label: "Address",
Default: conf.Addr.String,
},
ui.StringField{
form.StringField{
Key: "DB",
Label: "Database",
Default: conf.DB.String,
},
ui.StringField{
form.StringField{
Key: "Username",
Label: "Username",
Default: conf.Username.String,
},
ui.PasswordField{
form.PasswordField{
Key: "Password",
Label: "Password",
},
Expand All @@ -72,7 +72,7 @@ This will set the default server used when just "-o influxdb" is passed.`,
if !term.IsTerminal(int(syscall.Stdin)) { //nolint:unconvert
globalState.logger.Warn("Stdin is not a terminal, falling back to plain text input")
}
vals, err := form.Run(globalState.console.Stdin, globalState.console.Stdout)
vals, err := f.Run(globalState.console.Stdin, globalState.console.Stdout)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions ui/console/form/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package form implements elements for handling plain text and password inputs
// in the console.
package form
2 changes: 1 addition & 1 deletion ui/form.go → ui/console/form/form.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ui
package form

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion ui/form_fields.go → ui/console/form/form_fields.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ui
package form

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ui
package form

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion ui/form_test.go → ui/console/form/form_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ui
package form

import (
"bytes"
Expand Down

0 comments on commit 6ade203

Please sign in to comment.