diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 23:01:59 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 23:01:59 +0200 |
| commit | ed32c7fea5ad0fefccab9c99a51ebdae13b3a2f2 (patch) | |
| tree | 583f793af4287444346ff63d4a448625cc2346c9 /cmd | |
| parent | 57a7b5961037eb565d9cddc324bd0246daff440b (diff) | |
bump version to v0.2.0v0.2.0
- Add REPL mode with vi keybindings
- Add built-in commands (help, clear, quit/exit)
- Add mage repl target
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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") } |
