Skip to content

Commit

Permalink
fix: Prevent multiple executions with a warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Oct 9, 2020
1 parent 22f62a1 commit de90109
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions god.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"flag"
"fmt"
"io"
"math/rand"
"os"
"os/exec"
"strings"
"time"

"github.com/carmark/pseudo-terminal-go/terminal"
"github.com/common-nighthawk/go-figure"
Expand Down Expand Up @@ -188,6 +190,8 @@ cmdLoop:
showVersion()
case "git":
showCommands()
case "god":
showWarning()
case "sc":
showShortcuts()
case "alias":
Expand All @@ -197,12 +201,14 @@ cmdLoop:
gitCmd := buildCmd(line)
// Release the std in/out for preventing the
// git username & password input issues.
if strings.Contains(gitCmd, "push") {
if strings.Contains(gitCmd, " push") {
restartTerm = true
term.ReleaseFromStdInOut()
}
// Handle the execution of the input.
if retval := execCmd(true, "sh", "-c", gitCmd); len(retval) > 0 {
if strings.Contains(gitCmd, " god ") {
showWarning()
} else if retval := execCmd(true, "sh", "-c", gitCmd); len(retval) > 0 {
fmt.Fprintln(os.Stderr, retval)
}
// Restart the terminal for flushing the stdout.
Expand Down Expand Up @@ -260,6 +266,23 @@ func showCommands() {
table.Render()
}

// Show a warning from god.
func showWarning() {
messages := []string{
"Yes?",
"What?",
"Here.",
"What else do you want?",
"God hears you.",
"Hello, this is God. How may I be of assistance?",
"Repeating my name won't get you to the UNIX paradise.",
"You already have God's attention. Simply state your business.",
"Fetching God from a higher dimension... Please wait...",
}
rand.Seed(time.Now().Unix())
whiteColor.Println(messages[rand.Intn(len(messages))])
}

// Show commonly used git commands shortcuts.
func showShortcuts() {
table := tablewriter.NewWriter(os.Stdout)
Expand Down

0 comments on commit de90109

Please sign in to comment.