Skip to content

Commit 0dd3cd5

Browse files
committed
Fix
1 parent 4025495 commit 0dd3cd5

File tree

4 files changed

+59
-34
lines changed

4 files changed

+59
-34
lines changed

commands/run_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,3 +793,60 @@ func TestNewRunCommandJsonOutput(t *testing.T) {
793793
t.Errorf("unexpected scripts order or names: %v", output)
794794
}
795795
}
796+
797+
func TestNewRunCommandJsonOutputEmpty(t *testing.T) {
798+
f := newFakeKoolRun(nil, nil)
799+
f.parser.(*parser.FakeParser).MockScriptDetails = []parser.ScriptDetail{}
800+
801+
cmd := NewRunCommand(f)
802+
cmd.SetArgs([]string{"--json"})
803+
804+
if err := cmd.Execute(); err != nil {
805+
t.Errorf("unexpected error executing run command with --json; error: %v", err)
806+
}
807+
808+
fakeShell := f.shell.(*shell.FakeShell)
809+
810+
if len(fakeShell.OutLines) == 0 {
811+
t.Error("expected JSON output")
812+
return
813+
}
814+
815+
// Should output empty array, not null
816+
if fakeShell.OutLines[0] != "[]" {
817+
t.Errorf("expected empty JSON array '[]', got '%s'", fakeShell.OutLines[0])
818+
}
819+
}
820+
821+
func TestNewRunCommandJsonOutputNullSafety(t *testing.T) {
822+
f := newFakeKoolRun(nil, nil)
823+
f.parser.(*parser.FakeParser).MockScriptDetails = []parser.ScriptDetail{
824+
{
825+
Name: "test",
826+
Comments: nil, // nil comments
827+
Commands: nil, // nil commands
828+
},
829+
}
830+
831+
cmd := NewRunCommand(f)
832+
cmd.SetArgs([]string{"--json"})
833+
834+
if err := cmd.Execute(); err != nil {
835+
t.Errorf("unexpected error executing run command with --json; error: %v", err)
836+
}
837+
838+
fakeShell := f.shell.(*shell.FakeShell)
839+
840+
var output []parser.ScriptDetail
841+
if err := json.Unmarshal([]byte(fakeShell.OutLines[0]), &output); err != nil {
842+
t.Fatalf("failed to parse json output: %v", err)
843+
}
844+
845+
// Verify nil values are converted to empty arrays
846+
if output[0].Comments == nil {
847+
t.Error("Comments should not be nil in JSON output")
848+
}
849+
if output[0].Commands == nil {
850+
t.Error("Commands should not be nil in JSON output")
851+
}
852+
}

docs/05-Commands-Reference/0-kool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ kool
3434
* [kool recipe](kool-recipe) - Adds configuration for some recipe in the current work directory.
3535
* [kool restart](kool-restart) - Restart running service containers (the same as 'kool stop' followed by 'kool start')
3636
* [kool run](kool-run) - Execute a script defined in kool.yml
37-
* [kool scripts](kool-scripts) - List scripts defined in kool.yml
3837
* [kool self-update](kool-self-update) - Update kool to the latest version
3938
* [kool share](kool-share) - Live share your local environment on the Internet using an HTTP tunnel
4039
* [kool start](kool-start) - Start service containers defined in docker-compose.yml
4140
* [kool status](kool-status) - Show the status of all service containers
4241
* [kool stop](kool-stop) - Stop and destroy running service containers
42+

docs/05-Commands-Reference/kool-run.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ kool run SCRIPT [--] [ARG...]
1616
```
1717
-e, --env stringArray Environment variables.
1818
-h, --help help for run
19+
--json Output available scripts as JSON (use without script argument)
1920
```
2021

2122
### Options inherited from parent commands

docs/05-Commands-Reference/kool-scripts.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)