Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
boilr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
boilr
Commits
17747c72
Commit
17747c72
authored
8 years ago
by
Tamer Tas
Browse files
Options
Downloads
Patches
Plain Diff
pkg/util/tlog: pretty print multiple choice prompts
parent
93050447
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/prompt/prompt.go
+1
-1
1 addition, 1 deletion
pkg/prompt/prompt.go
pkg/prompt/prompt_test.go
+1
-1
1 addition, 1 deletion
pkg/prompt/prompt_test.go
pkg/util/tlog/log.go
+19
-3
19 additions, 3 deletions
pkg/util/tlog/log.go
with
21 additions
and
5 deletions
pkg/prompt/prompt.go
+
1
−
1
View file @
17747c72
...
...
@@ -68,7 +68,7 @@ func (p boolPrompt) EvaluateChoice(c string) (interface{}, error) {
type
multipleChoicePrompt
[]
string
func
(
p
multipleChoicePrompt
)
PromptMessage
(
name
string
)
string
{
return
fmt
.
Sprintf
(
"Please choose an
index
for %q"
,
name
)
return
fmt
.
Sprintf
(
"Please choose an
option
for %q"
,
name
)
}
func
(
p
multipleChoicePrompt
)
EvaluateChoice
(
c
string
)
(
interface
{},
error
)
{
...
...
This diff is collapsed.
Click to expand it.
pkg/prompt/prompt_test.go
+
1
−
1
View file @
17747c72
...
...
@@ -90,7 +90,7 @@ func TestMultipleChoicePromptFunc(t *testing.T) {
msg
:=
slicePrompt
.
PromptMessage
(
name
)
expectedPromptMsg
:=
"Please choose an
index
for
\"
fieldName
\"
"
expectedPromptMsg
:=
"Please choose an
option
for
\"
fieldName
\"
"
if
msg
!=
expectedPromptMsg
{
t
.
Errorf
(
"slicePrompt(%q).PromptMessage(%q) expected %q got %q"
,
defval
,
name
,
expectedPromptMsg
,
msg
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/util/tlog/log.go
+
19
−
3
View file @
17747c72
...
...
@@ -135,11 +135,27 @@ func Fatal(msg string) {
// Prompt outputs the given message as a question along with a default value.
func
Prompt
(
msg
string
,
defval
interface
{})
{
fmt
.
Print
(
strings
.
Join
(
[]
string
{
tokens
:=
[]
string
{
color
.
New
(
color
.
FgBlue
)
.
SprintFunc
()(
"["
+
QuestionMark
+
"]"
),
color
.
New
(
color
.
Bold
,
color
.
FgWhite
)
.
SprintFunc
()(
msg
),
color
.
New
(
color
.
FgBlue
)
.
SprintFunc
()(
fmt
.
Sprintf
(
"[default: %#v]: "
,
defval
)),
},
" "
))
}
// TODO refactor & eliminate duplication
switch
val
:=
defval
.
(
type
)
{
case
[]
interface
{}
:
tokens
=
append
(
tokens
,
"
\n
"
)
for
i
,
v
:=
range
val
{
tokens
=
append
(
tokens
,
color
.
New
(
color
.
Bold
,
color
.
FgWhite
)
.
SprintFunc
()(
fmt
.
Sprintf
(
" %v - %#v
\n
"
,
i
+
1
,
v
)))
}
tokens
=
append
(
tokens
,
color
.
New
(
color
.
Bold
,
color
.
FgWhite
)
.
SprintFunc
()(
fmt
.
Sprintf
(
" Choose from %v..%v"
,
1
,
len
(
val
))))
tokens
=
append
(
tokens
,
color
.
New
(
color
.
Bold
,
color
.
FgBlue
)
.
SprintFunc
()(
fmt
.
Sprintf
(
"[default: %v]: "
,
1
)))
default
:
tokens
=
append
(
tokens
,
color
.
New
(
color
.
Bold
,
color
.
FgBlue
)
.
SprintFunc
()(
fmt
.
Sprintf
(
"[default: %#v]: "
,
defval
)))
}
fmt
.
Print
(
strings
.
Join
(
tokens
,
" "
))
}
// TODO use dependency injection wrapper for fmt.Print usage in the code base
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment