Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reinput yes or no #15

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 22 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,10 @@ import (
"bytes"
"context"
"crypto/rand"
"errors"
"flag"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
@@ -275,16 +277,27 @@ func createJob(f *os.File, job *batchv1.Job) error {
return err
}

fmt.Fprint(tty.Output(), "Do you want to create a job with the change you just made? [y/N]\n")
answer, err := ttyutil.ReadLine(tty)
if err != nil {
return err
}
answer = strings.TrimSpace(answer)
if answer != "Y" && answer != "y" {
fmt.Println("canceled")
return nil
for {
fmt.Fprint(tty.Output(), "Do you want to create a job with the change you just made? [y/N]\n")
answer, err := ttyutil.ReadLine(tty)
if err != nil {
if errors.Is(err, io.EOF) {
continue
}
return err
}

switch strings.ToLower(strings.TrimSpace(answer)) {
case "y":
goto yes
case "n":
fmt.Fprintln(tty.Output(), "canceled")
return nil
default:
continue
}
}
yes:

cmd = exec.Command("kubectl", "apply", "-f", f.Name())
cmd.Stdin = tty.Input()