Compare commits
2 Commits
ff1a4a4387
...
70476f2c51
| Author | SHA1 | Date | |
|---|---|---|---|
|
70476f2c51
|
|||
|
ccc496f55f
|
@@ -130,11 +130,12 @@ func main() {
|
|||||||
defer toErr(&err)
|
defer toErr(&err)
|
||||||
isattyStd()
|
isattyStd()
|
||||||
br := bufio.NewReader(os.Stdin)
|
br := bufio.NewReader(os.Stdin)
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
retry:
|
||||||
v.Title = require(promptTrimNoEmpty(br, "Title: "))
|
v.Title = require(promptTrimNoEmpty(br, "Title: "))
|
||||||
v.Category = require(prompt(br, "Category: "))
|
v.Category = require(prompt(br, "Category: "))
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
year := require(promptUintFallbackBounds(
|
year := require(promptUintFallbackBounds(
|
||||||
br, "Year: ",
|
br, "Year: ",
|
||||||
1970, uint64(now.Year()),
|
1970, uint64(now.Year()),
|
||||||
@@ -161,6 +162,11 @@ func main() {
|
|||||||
time.UTC,
|
time.UTC,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
printVOD(v)
|
||||||
|
if !require(promptBool(br, "Proceed? ", true)) {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
if resp, err = http.DefaultClient.Do(req); err != nil {
|
if resp, err = http.DefaultClient.Do(req); err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -126,6 +126,40 @@ invalid:
|
|||||||
return v, true
|
return v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// promptBool prompts the user for a y/n response until a valid response or a
|
||||||
|
// single newline character is read.
|
||||||
|
func promptBool(
|
||||||
|
br *bufio.Reader,
|
||||||
|
p string,
|
||||||
|
fallback bool,
|
||||||
|
) (bool, bool) {
|
||||||
|
if fallback {
|
||||||
|
p += "[Y/n] "
|
||||||
|
} else {
|
||||||
|
p += "[y/N] "
|
||||||
|
}
|
||||||
|
|
||||||
|
invalid:
|
||||||
|
s, ok := prompt(br, p)
|
||||||
|
if !ok {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch strings.ToLower(strings.TrimSpace(s)) {
|
||||||
|
default:
|
||||||
|
goto invalid
|
||||||
|
|
||||||
|
case "":
|
||||||
|
return fallback, true
|
||||||
|
|
||||||
|
case "y":
|
||||||
|
return true, true
|
||||||
|
|
||||||
|
case "n":
|
||||||
|
return false, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// require panics with an error if ok is false, and returns v otherwise.
|
// require panics with an error if ok is false, and returns v otherwise.
|
||||||
func require[T any](v T, ok bool) T {
|
func require[T any](v T, ok bool) T {
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user