Skip to content

Commit 4025495

Browse files
committed
Improve
1 parent e85e255 commit 4025495

2 files changed

Lines changed: 132 additions & 17 deletions

File tree

commands/run_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package commands
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67
"io"
@@ -745,3 +746,50 @@ func TestNewRunCommandWithTypoErrorCancelled(t *testing.T) {
745746
t.Errorf("expecting warning '%s', got '%s'", expected, output)
746747
}
747748
}
749+
750+
func TestNewRunCommandJsonOutput(t *testing.T) {
751+
f := newFakeKoolRun(nil, nil)
752+
f.parser.(*parser.FakeParser).MockScriptDetails = []parser.ScriptDetail{
753+
{
754+
Name: "setup",
755+
Comments: []string{"Sets up dependencies"},
756+
Commands: []string{"kool run composer install"},
757+
},
758+
{
759+
Name: "lint",
760+
Comments: []string{},
761+
Commands: []string{"kool run go:linux fmt ./..."},
762+
},
763+
}
764+
765+
cmd := NewRunCommand(f)
766+
cmd.SetArgs([]string{"--json"})
767+
768+
if err := cmd.Execute(); err != nil {
769+
t.Errorf("unexpected error executing run command with --json; error: %v", err)
770+
}
771+
772+
if !f.parser.(*parser.FakeParser).CalledParseAvailableDetails {
773+
t.Error("did not call ParseAvailableScriptsDetails")
774+
}
775+
776+
fakeShell := f.shell.(*shell.FakeShell)
777+
778+
if len(fakeShell.OutLines) == 0 {
779+
t.Error("expected JSON output")
780+
return
781+
}
782+
783+
var output []parser.ScriptDetail
784+
if err := json.Unmarshal([]byte(fakeShell.OutLines[0]), &output); err != nil {
785+
t.Fatalf("failed to parse json output: %v", err)
786+
}
787+
788+
if len(output) != 2 {
789+
t.Fatalf("expected 2 script entries, got %d", len(output))
790+
}
791+
792+
if output[0].Name != "lint" || output[1].Name != "setup" {
793+
t.Errorf("unexpected scripts order or names: %v", output)
794+
}
795+
}

skills/kool/SKILL.md

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,106 @@
11
---
22
name: kool
3-
description: Discovers and runs project scripts with the kool CLI. Use when the user wants to list custom commands from kool.yml, understand project tasks, or run kool scripts. Use --json flag for machine-readable output.
3+
description: Docker development environment CLI. Use for managing containers (start/stop/restart), executing commands in services, viewing logs, and running project scripts from kool.yml.
44
---
55

66
# Kool CLI
77

8-
Use kool to discover and run project scripts defined in `kool.yml`.
8+
Kool simplifies Docker-based development with commands for container lifecycle, service execution, and custom scripts.
99

10-
## Quick Start
10+
## Quick Reference
1111

1212
```bash
13-
kool run --json # List scripts as JSON
14-
kool run <script> # Run a script
13+
kool start # Start all services from docker-compose.yml
14+
kool stop # Stop all services
15+
kool restart --rebuild # Restart and rebuild images
16+
kool status # Show running containers
17+
kool exec <service> <cmd> # Run command in service container
18+
kool logs -f <service> # Follow service logs
19+
kool run --json # List available scripts as JSON
20+
kool run <script> # Run a script from kool.yml
1521
```
1622

17-
## Core Workflow
23+
## Service Lifecycle
1824

19-
1. Work from the project root (has `kool.yml`) or use `-w` to point to it.
20-
2. Discover scripts:
25+
Services are defined in `docker-compose.yml`. Kool wraps docker-compose with simpler commands.
2126

2227
```bash
23-
kool run --json # Preferred: returns [{name, comments, commands}]
24-
kool run # Human-readable list
28+
kool start # Start all services
29+
kool start app database # Start specific services
30+
kool start --rebuild # Rebuild images before starting
31+
kool start --foreground # Run in foreground (see logs)
32+
kool start --profile worker # Enable a docker-compose profile
33+
34+
kool stop # Stop all services
35+
kool stop app # Stop specific service
36+
kool stop --purge # Stop and remove volumes (destructive)
37+
38+
kool restart # Restart all services
39+
kool restart --rebuild # Rebuild images on restart
40+
kool restart --purge # Purge volumes on restart
41+
42+
kool status # Show status of all containers
43+
```
44+
45+
## Executing Commands in Containers
46+
47+
Use `exec` to run commands inside running service containers (like SSH).
48+
49+
```bash
50+
kool exec <service> <command>
51+
kool exec app bash # Interactive shell
52+
kool exec app php artisan migrate # Run Laravel migration
53+
kool exec app npm install # Install npm packages
54+
kool exec -e VAR=value app env # With environment variable
2555
```
2656

27-
3. Run scripts:
57+
## One-off Docker Containers
58+
59+
Use `docker` to run commands in temporary containers (not services).
60+
61+
```bash
62+
kool docker <image> <command>
63+
kool docker node npm init # Run npm in node container
64+
kool docker --volume=$PWD:/app golang go build # Mount current dir
65+
kool docker --env=DEBUG=1 python python script.py # With env var
66+
kool docker --publish=3000:3000 node npm start # Expose port
67+
```
68+
69+
## Viewing Logs
70+
71+
```bash
72+
kool logs # Last 25 lines from all services
73+
kool logs app # Logs from specific service
74+
kool logs -f # Follow logs (live)
75+
kool logs -f app worker # Follow multiple services
76+
kool logs --tail 100 # Last 100 lines
77+
kool logs --tail 0 # All logs
78+
```
79+
80+
## Project Scripts
81+
82+
Scripts are defined in `kool.yml` and provide project-specific commands.
83+
84+
```bash
85+
kool run --json # List scripts as JSON [{name, comments, commands}]
86+
kool run # List scripts (human-readable)
87+
kool run <script> # Run a script
88+
kool run <script> -- <args> # Pass args (single-line scripts only)
89+
kool run -e VAR=1 <script> # Run with environment variable
90+
```
91+
92+
## Global Options
93+
94+
All commands support:
2895

2996
```bash
30-
kool run <script>
31-
kool run <script> -- <args>
97+
-w, --working_dir <path> # Run from different directory
98+
--verbose # Increase output verbosity
3299
```
33100

34101
## Important Rules
35102

36-
- **ALWAYS** run commands from the project root or use `-w/--working_dir`.
37-
- **ONLY** pass extra args to single-line scripts; multi-line scripts reject extra args.
38-
- **REMEMBER** `kool.yml` scripts are not full bash (no pipes/conditionals); use `kool docker <image> bash -c "..."` for complex shell logic.
39-
- **CHECK** `kool.yml` or `kool.yaml` in the project root and `~/kool` for shared scripts.
103+
- **ALWAYS** run from project root (has `docker-compose.yml` and `kool.yml`) or use `-w`.
104+
- **Service names** come from `docker-compose.yml` service definitions.
105+
- **Script args** only work with single-line scripts; multi-line scripts reject extra args.
106+
- **Scripts** in `kool.yml` are not full bash - use `kool docker <image> bash -c "..."` for pipes/conditionals.

0 commit comments

Comments
 (0)