Skip to content

Commit 0e7eaf5

Browse files
committed
Refactor code structure and remove redundant code blocks for improved readability and maintainability
0 parents  commit 0e7eaf5

29 files changed

Lines changed: 5798 additions & 0 deletions

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
dist/
8+
build/
9+
*.egg-info/
10+
*.egg
11+
12+
# Virtual environment
13+
.venv/
14+
venv/
15+
env/
16+
17+
# Testing / coverage
18+
.pytest_cache/
19+
.coverage
20+
htmlcov/
21+
.tox/
22+
.nox/
23+
24+
# Ruff
25+
.ruff_cache/
26+
27+
# ty
28+
.ty/
29+
30+
# IDE
31+
.idea/
32+
.vscode/
33+
*.swp
34+
*.swo
35+
36+
# OS
37+
.DS_Store
38+
Thumbs.db
39+
40+
# Environment variables
41+
.env
42+
.env.local

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

.rumdl.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# rumdl configuration file
2+
3+
# Global configuration options
4+
[global]
5+
# List of rules to disable (uncomment and modify as needed)
6+
disable = ["MD013", "MD033", "MD041", "MD036"]
7+
8+
# List of file/directory patterns to exclude from linting
9+
exclude = [
10+
# Common directories to exclude
11+
".git",
12+
".github",
13+
"node_modules",
14+
"vendor",
15+
"dist",
16+
"build",
17+
".venv",
18+
"venv",
19+
"__pycache__",
20+
"*.egg-info",
21+
22+
# Specific files or patterns
23+
"CHANGELOG.md",
24+
]

AGENTS.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Shellflow Agent Instructions
2+
3+
## Project Overview
4+
5+
Shellflow is a minimal shell script orchestrator with SSH support. It allows users to write shell scripts that execute across local and remote environments using simple comment markers.
6+
7+
## Project Structure
8+
9+
```text
10+
shellflow/
11+
├── src/shellflow.py # Main module with all functionality
12+
├── tests/ # Unit tests (pytest)
13+
├── features/ # BDD acceptance tests (behave)
14+
│ ├── parser.feature
15+
│ ├── runner.feature
16+
│ ├── steps/shellflow_steps.py
17+
│ └── environment.py
18+
├── behave_runner.py # Wrapper for running behave
19+
├── pyproject.toml # Project configuration
20+
├── README.md # Documentation
21+
└── AGENTS.md # This file
22+
```
23+
24+
## Core Concepts
25+
26+
### Script Block Markers
27+
28+
- `# @LOCAL` - Start a local execution block
29+
- `# @REMOTE <host>` - Start a remote execution block
30+
31+
### Key Modules
32+
33+
- `Block` - Represents an execution block (local or remote)
34+
- `ExecutionContext` - Passes state between block executions
35+
- `ExecutionResult` - Result of executing a single block
36+
- `RunResult` - Result of running a complete script
37+
- `SSHConfig` - SSH configuration for remote hosts
38+
39+
### CLI Commands
40+
41+
```bash
42+
shellflow run <script> # Run a shellflow script
43+
shellflow run <script> -v # Run with verbose output
44+
shellflow --version # Show version
45+
```
46+
47+
## Development Commands
48+
49+
```bash
50+
just format # Format code with ruff
51+
just lint # Lint with ruff
52+
just test # Run pytest
53+
just bdd # Run behave BDD tests
54+
just test-all # Run format, lint, test, and bdd
55+
just typecheck # Type check with ty
56+
```
57+
58+
## Testing
59+
60+
- Unit tests: `pytest` under `tests/`
61+
- BDD tests: `behave` under `features/`
62+
- Run all: `just test-all`
63+
64+
## Dependencies
65+
66+
- Runtime: `paramiko>=3.0.0`
67+
- Dev: `pytest`, `behave`, `ruff`, `ty`, `hypothesis`

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

Justfile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Default recipe to display help
2+
default:
3+
@just --list
4+
5+
# Sync all dependencies
6+
sync:
7+
uv sync --all-groups
8+
9+
# Format all code
10+
format:
11+
rumdl fmt .
12+
uv run ruff format .
13+
uv run ruff check --fix .
14+
15+
# Auto-fix linting issues
16+
fix:
17+
rumdl check --fix .
18+
uv run ruff check --fix .
19+
20+
# Run all lints
21+
lint:
22+
typos
23+
rumdl check .
24+
uv run ruff check .
25+
uv run ruff format --check .
26+
uv run ty check src tests
27+
28+
# Run tests
29+
test:
30+
uv run pytest
31+
32+
# Run BDD scenarios
33+
bdd:
34+
uv run behave
35+
36+
# Run both TDD and BDD suites
37+
test-all:
38+
uv run pytest
39+
uv run behave
40+
41+
# Run tests with coverage
42+
test-coverage:
43+
uv run pytest --cov=uv_app --cov-report=term-missing --cov-report=html
44+
45+
# Run benchmarks
46+
bench:
47+
uv run pytest -m benchmark --benchmark-only
48+
49+
# Build the package
50+
build:
51+
uv build
52+
53+
# Type check with ty
54+
typecheck:
55+
uv run ty check src tests
56+
57+
# Check for Chinese characters
58+
check-cn:
59+
rg --line-number --column "\p{Han}"
60+
61+
# Full CI check
62+
ci: lint test-all build
63+
64+
# ============================================================
65+
# Maintenance & Tools
66+
# ============================================================
67+
68+
# Clean build artifacts
69+
clean:
70+
rm -rf dist/ .pytest_cache/ .ruff_cache/ htmlcov/ .coverage
71+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
72+
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
73+
74+
# Install all required development tools
75+
setup:
76+
uv sync --all-groups
77+
cargo install typos-cli
78+
79+
# Lock dependencies
80+
lock:
81+
uv lock
82+
83+
# Update all dependencies
84+
update:
85+
uv lock --upgrade

README.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Shellflow
2+
3+
A minimal shell script orchestrator with SSH support. Shellflow allows you to write shell scripts that execute across local and remote environments using simple comment markers.
4+
5+
## Features
6+
7+
- **Block-based execution**: Use comment markers to define local and remote execution blocks
8+
- **SSH support**: Automatically reads SSH configuration from `~/.ssh/config`
9+
- **Fail-fast execution**: Stops on first error with clear error reporting
10+
- **Context passing**: The previous block output is passed via `SHELLFLOW_LAST_OUTPUT`
11+
- **CLI interface**: Simple command-line tool for running scripts
12+
13+
## Installation
14+
15+
```bash
16+
# Install the package and dependencies
17+
uv sync --all-groups
18+
19+
# Install in development mode
20+
uv pip install -e .
21+
```
22+
23+
## Usage
24+
25+
### Writing Scripts
26+
27+
Shellflow scripts use comment markers to define execution blocks:
28+
29+
```bash
30+
# @LOCAL
31+
echo "Running locally"
32+
33+
# @REMOTE myserver
34+
echo "Running on myserver"
35+
36+
# @LOCAL
37+
echo "Back to local"
38+
```
39+
40+
### Running Scripts
41+
42+
```bash
43+
# Run a script
44+
shellflow run script.sh
45+
46+
# Run with verbose output
47+
shellflow run script.sh --verbose
48+
shellflow run script.sh -v
49+
50+
# Use a non-default SSH config file
51+
shellflow run script.sh --ssh-config ./ssh_config
52+
```
53+
54+
### SSH Configuration
55+
56+
Shellflow reads SSH configuration from `~/.ssh/config`. The following options are supported:
57+
58+
```ssh
59+
Host myserver
60+
HostName 192.168.1.100
61+
User admin
62+
Port 2222
63+
IdentityFile ~/.ssh/myserver_key
64+
```
65+
66+
If `paramiko` is installed, it will be used for parsing. Otherwise, a basic parser is used as fallback.
67+
68+
### Execution Model
69+
70+
Blocks are intentionally stateless. Shell state such as `cd`, shell variables, and `export` commands do not persist into the next block. If you need to pass data forward, use the previous block output via `SHELLFLOW_LAST_OUTPUT`:
71+
72+
```bash
73+
# @LOCAL
74+
echo "Step 1 output"
75+
76+
# @LOCAL
77+
echo "Previous output was: $SHELLFLOW_LAST_OUTPUT"
78+
```
79+
80+
Lines before the first marker, such as a shebang or shared shell options, are prepended to every block. That lets you define common guardrails once:
81+
82+
```bash
83+
#!/bin/bash
84+
set -euo pipefail
85+
86+
# @LOCAL
87+
echo "runs with the shared prelude"
88+
89+
# @REMOTE myserver
90+
echo "remote block gets the same prelude"
91+
```
92+
93+
## Testing
94+
95+
### Unit Tests (pytest)
96+
97+
Run unit tests with pytest:
98+
99+
```bash
100+
# Run all tests
101+
just test
102+
103+
# Run specific test file
104+
uv run pytest tests/test_shellflow.py
105+
106+
# Run with coverage
107+
uv run pytest --cov=shellflow --cov-report=term-missing
108+
```
109+
110+
### BDD Tests (behave)
111+
112+
Run acceptance tests with behave:
113+
114+
```bash
115+
# Run BDD tests
116+
just bdd
117+
118+
# Or directly
119+
uv run behave
120+
```
121+
122+
### Running All Tests
123+
124+
```bash
125+
# Run format, lint, test, and BDD
126+
just test-all
127+
```
128+
129+
## Development Commands
130+
131+
```bash
132+
just format # Format code with ruff
133+
just lint # Lint with ruff
134+
just test # Run pytest
135+
just bdd # Run behave BDD tests
136+
just test-all # Run format, lint, test, and bdd
137+
just typecheck # Type check with ty
138+
```
139+
140+
## Project Structure
141+
142+
```text
143+
shellflow/
144+
├── src/shellflow.py # Main module
145+
├── tests/ # Unit tests
146+
├── features/ # BDD feature files
147+
│ ├── parser.feature
148+
│ └── runner.feature
149+
├── pyproject.toml # Project configuration
150+
└── README.md
151+
```
152+
153+
## CLI Reference
154+
155+
```text
156+
shellflow run <script> # Run a shellflow script
157+
shellflow run <script> -v # Run with verbose output
158+
shellflow --version # Show version
159+
```
160+
161+
## License
162+
163+
Apache-2.0

0 commit comments

Comments
 (0)