From 8dd11f40701a2f477b1e5e2a6db7c10097be7ceb Mon Sep 17 00:00:00 2001 From: Walfie Date: Mon, 18 Mar 2019 16:54:27 -0400 Subject: [PATCH 1/2] Ignore input lines starting with `#` (comments) Readline (and thus rlwrap) has the ability to comment out the current input line by pressing `esc` followed by `#`. However, kubectl-repl will execute this as `kubectl #insert comment here` which shows the help text. This updates the repl to ignore lines beginning with `#`. --- main/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.go b/main/main.go index 0308d34..a4fc4c9 100644 --- a/main/main.go +++ b/main/main.go @@ -56,7 +56,7 @@ func repl(commands Commands) error { return err } - if strings.TrimSpace(command) == "" { + if trimmed := strings.TrimSpace(command); trimmed == "" || strings.HasPrefix(trimmed, "#") { return nil } From 2a01819a7eb7f393bccfa8a5721a7456cc5ccc82 Mon Sep 17 00:00:00 2001 From: Walfie Date: Tue, 19 Mar 2019 10:25:43 -0400 Subject: [PATCH 2/2] Move `#` prefix check to builtin-shell Also refactor whitespace trimming (which includes newlines) --- main/builtin-shell.go | 2 +- main/main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main/builtin-shell.go b/main/builtin-shell.go index c06710e..5793532 100644 --- a/main/builtin-shell.go +++ b/main/builtin-shell.go @@ -11,7 +11,7 @@ func (b builtinShell) init() error { } func (b builtinShell) filter(command string) bool { - return strings.HasPrefix(command, ";") + return strings.HasPrefix(command, ";") || strings.HasPrefix(command, "#") } func (b builtinShell) run(command string) error { diff --git a/main/main.go b/main/main.go index a4fc4c9..d0f23a1 100644 --- a/main/main.go +++ b/main/main.go @@ -41,7 +41,7 @@ func prompt() (string, error) { if err != nil { return "", err } - response := strings.Trim(line, "\n") + response := strings.TrimSpace(line) return substituteForVars(response) } @@ -56,7 +56,7 @@ func repl(commands Commands) error { return err } - if trimmed := strings.TrimSpace(command); trimmed == "" || strings.HasPrefix(trimmed, "#") { + if command == "" { return nil }