Skip to content

Conversation

@alexo-bunnyshell
Copy link
Contributor

Summary

This PR implements a new top-level bns exec utility command that allows running arbitrary commands in component containers, similar to kubectl exec and docker exec.

Command Structure

  • Positional argument: bns exec <component-id> instead of bns exec --id <id>
  • Context fallback: Works without component ID if set in context
  • Top-level utility: Registered alongside git, port-forward, and other utilities

Key Features

  • Execute arbitrary commands in component containers
  • Interactive or explicit pod/container selection via wizards
  • TTY and stdin control via --tty and --stdin flags (no shorthands to avoid global -t timeout flag conflict)
  • Defaults to interactive shell (/bin/sh) when no command specified
  • Auto-enables --tty and --stdin for interactive shells
  • Supports namespace/pod-name format for pod specification
  • Reuses existing K8s exec infrastructure (pkg/k8s/kubectl/exec)

Usage Examples

# Interactive shell (auto-enables --tty --stdin)
bns exec comp-123

# Run command
bns exec comp-123 -- ls -la /app

# With explicit flags
bns exec comp-123 --tty --stdin --pod my-pod -c api -- /bin/bash

# From context (no ID needed)
bns configure set-context --component comp-123
bns exec --tty --stdin

# Pipe local file to remote container
bns exec comp-123 --stdin -- python3 < script.py

Implementation

  • New directory: cmd/exec/
  • New file: cmd/exec/root.go (245 lines)
  • Modified: cmd/utils/root.go (registered exec command)
  • Pattern: Follows other utility commands (git, port-forward)

alexo-bunnyshell and others added 2 commits January 18, 2026 00:57
Implements a new top-level 'bns exec' utility command that allows running
arbitrary commands in component containers, similar to kubectl exec and
docker exec.

Command Structure:
- Component ID as positional argument: bns exec <component-id>
- Falls back to context if component ID not provided
- Registered as top-level utility command (not under 'bns components')

Features:
- Execute arbitrary commands in component containers
- Interactive or explicit pod/container selection via wizards
- TTY and stdin control via --tty and --stdin flags (no shorthands)
- Defaults to interactive shell (/bin/sh) when no command specified
- Auto-enables --tty and --stdin for interactive shells
- Supports namespace/pod-name format for pod specification
- Reuses existing K8s exec infrastructure (pkg/k8s/kubectl/exec)

Implementation:
- New directory: cmd/exec/
- New file: cmd/exec/root.go (245 lines)
- Modified: cmd/utils/root.go (registered exec command)
- Pattern follows other utility commands (git, port-forward)

Usage Examples:
- Interactive shell: bns exec comp-123
- Run command: bns exec comp-123 -- ls -la /app
- With flags: bns exec comp-123 --tty --stdin --pod my-pod -c api
- From context: bns configure set-context --component comp-123; bns exec
- Pipe input: bns exec comp-123 --stdin -- python3 < script.py

Documentation:
- Updated CLAUDE.md with comprehensive exec command documentation
- Added "Utility Commands" section with usage examples
- Updated workflow examples to use new command syntax
- Documented positional argument pattern and flag conflicts
- Added design notes about global flag conflicts

Design Decisions:
- Positional component ID instead of --id flag (cleaner UX)
- No shorthand flags to avoid conflict with global -t (timeout) flag
- Follows docker/kubectl conventions for TTY and stdin handling
- Auto-detection of interactive mode when no command specified

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Move examples from Long to Example field for proper Cobra formatting
- Remove manual Flags documentation from Long field
- Let Cobra automatically generate the Flags section
- Improves help readability by eliminating duplication
@alexo-bunnyshell alexo-bunnyshell merged commit f9f9c73 into master Jan 19, 2026
1 check passed
@alexo-bunnyshell alexo-bunnyshell deleted the feature/add-exec-command branch January 19, 2026 16:03
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.

2 participants