Skip to content

cli, cmd: add 'shell' command and '!' prefix for local shell execution - #231

Open
Paramveersingh-S wants to merge 1 commit into
apache:mainfrom
Paramveersingh-S:feat/shell-exec
Open

Paramveersingh-S wants to merge 1 commit into
apache:mainfrom
Paramveersingh-S:feat/shell-exec

Conversation

@Paramveersingh-S

Copy link
Copy Markdown

Fixes #215

Problem

Operators working inside the interactive cmk shell prompt (or scripting cmk) could not run local OS shell commands (e.g., ls -lR /etc/cloudstack/extensions/) directly from the cmk prompt as they could in legacy Python CloudMonkey (! / shell).

Solution

  1. cmd/shell.go:
    • Registers the built-in shell command (shell <command>) and RunShellCommand(command string).
    • Uses $SHELL -c <command> (falling back to sh -c) on Unix-like systems and cmd /C <command> on Windows, wiring os.Stdin, os.Stdout, and os.Stderr directly.
  2. cli/exec.go:
    • Supports both the !<command> shorthand (e.g., !ls -lR /etc/cloudstack/extensions/ or ! ls -la) and shell <command> in ExecLine, passing the raw command string to the system shell so shell pipelines, globs, and redirections work naturally.
  3. cli/exec_test.go:
    • Adds unit tests verifying !echo ..., shell echo ..., empty shell error handling, and bare ! no-op behavior.

Verification / Solution Proof

$ go test -mod=vendor -v ./cli ./cmd ./config
=== RUN   TestFindAutocompleteAPIRelatedNounMatch
--- PASS: TestFindAutocompleteAPIRelatedNounMatch (0.00s)
...
=== RUN   TestExecLineBangShellCommand
--- PASS: TestExecLineBangShellCommand (0.04s)
=== RUN   TestExecLineShellCommand
--- PASS: TestExecLineShellCommand (0.03s)
=== RUN   TestExecLineEmptyShellCommandReturnsError
--- PASS: TestExecLineEmptyShellCommandReturnsError (0.00s)
PASS
ok  	github.com/apache/cloudstack-cloudmonkey/cli

Copilot AI balanced review requested due to automatic review settings November 23, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Paramveersingh-S

Copy link
Copy Markdown
Author

cc @DaanHoogland @vishesh92 for review whenever you get a chance — implements shell and ! prefix support for local shell command execution (#215).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shell exec possibility

2 participants