Skip to content
GitLab
Explore
Sign in
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
Container 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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Bei Problemen mit der SSH-Verbindung können sie den bestehenden SSH-Key neu hochladen.
Show more breadcrumbs
ifs
boilr
Commits
26d3a00b
Commit
26d3a00b
authored
9 years ago
by
Tamer Tas
Browse files
Options
Downloads
Patches
Plain Diff
Add input scanning utilities
parent
f363298b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/util/inpututil/scan.go
+56
-0
56 additions, 0 deletions
pkg/util/inpututil/scan.go
with
56 additions
and
0 deletions
pkg/util/inpututil/scan.go
0 → 100644
+
56
−
0
View file @
26d3a00b
package
inpututil
import
(
"fmt"
"strings"
)
var
(
booleanValues
=
map
[
string
]
bool
{
"y"
:
true
,
"yes"
:
true
,
"yup"
:
true
,
"n"
:
false
,
"no"
:
false
,
"nope"
:
false
,
}
)
func
ScanYesOrNo
(
msg
string
,
def
bool
)
(
bool
,
error
)
{
var
choices
string
if
def
{
choices
=
"Y/n"
}
else
{
choices
=
"y/N"
}
fmt
.
Print
(
msg
,
" "
,
choices
,
" "
)
var
choice
string
_
,
err
:=
fmt
.
Scanf
(
"%s"
,
&
choice
)
if
err
!=
nil
{
return
def
,
err
}
switch
val
,
ok
:=
booleanValues
[
strings
.
ToLower
(
choice
)];
{
case
ok
:
return
val
,
nil
case
choice
==
""
:
return
def
,
nil
}
return
def
,
fmt
.
Errorf
(
"unrecognized choice %#q"
,
choice
)
}
func
ScanValue
(
msg
string
)
(
string
,
error
)
{
fmt
.
Print
(
msg
)
var
value
string
_
,
err
:=
fmt
.
Scanf
(
"%s"
,
&
value
)
if
err
!=
nil
{
return
""
,
err
}
return
value
,
nil
}
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