diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/perc/main.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cmd/perc/main.go b/cmd/perc/main.go index a5764b5..a9faf76 100644 --- a/cmd/perc/main.go +++ b/cmd/perc/main.go @@ -7,6 +7,8 @@ import ( "codeberg.org/snonux/perc/internal" "codeberg.org/snonux/perc/internal/calculator" + "codeberg.org/snonux/perc/internal/repl" + "github.com/mattn/go-isatty" ) func main() { @@ -20,6 +22,11 @@ func main() { func runCommand(args []string) (string, error) { if len(args) < 2 { + // No args provided - check if stdin is a TTY for REPL mode + if isatty.IsTerminal(os.Stdin.Fd()) { + repl.RunREPL() + return "", nil + } printUsage() return "", fmt.Errorf("no input provided") } @@ -28,6 +35,12 @@ func runCommand(args []string) (string, error) { return internal.Version, nil } + // Check for --repl flag + if args[1] == "--repl" || args[1] == "repl" { + repl.RunREPL() + return "", nil + } + input := strings.Join(args[1:], " ") result, err := calculator.Parse(input) if err != nil { @@ -40,9 +53,12 @@ func runCommand(args []string) (string, error) { func printUsage() { fmt.Println("Usage: perc <calculation>") fmt.Println(" perc version") + fmt.Println(" perc [--repl|repl]") fmt.Println("\nExamples:") fmt.Println(" perc 20% of 150") fmt.Println(" perc what is 20% of 150") fmt.Println(" perc 30 is what % of 150") fmt.Println(" perc 30 is 20% of what") + fmt.Println("\nStart REPL mode interactively by running without arguments:") + fmt.Println(" perc") } |
