Skip to content

Commit 4d4200f

Browse files
committed
fix: address PR review comments (#3, #4, #5)
- --help now always takes precedence over --doc regardless of arg order - Updated AsMain doc comment to document all invocation modes - Removed no-op strings.TrimPrefix in test assertion Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
1 parent c1de216 commit 4d4200f

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

go/fn/run.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,20 @@ func WithDocs(readme []byte, meta []byte) Option {
4242
}
4343
}
4444

45-
// AsMain evaluates the ResourceList from STDIN to STDOUT.
45+
// AsMain evaluates a KRM function. By default it reads a ResourceList from
46+
// STDIN, processes it, and writes the result to STDOUT.
47+
//
4648
// `input` can be
4749
// - a `ResourceListProcessor` which implements `Process` method
4850
// - a function `Runner` which implements `Run` method
4951
//
50-
// Options configure additional behavior such as --help and --doc support
52+
// Invocation modes (checked in this order):
53+
// - --help: prints human-readable documentation to STDOUT and returns nil.
54+
// - --doc: prints machine-readable JSON documentation to STDOUT and returns nil.
55+
// - positional file args: reads KRM resources from files instead of STDIN.
56+
// - no args: reads ResourceList from STDIN (default behavior).
57+
//
58+
// Options configure additional behavior such as documentation support
5159
// via WithDocs. Existing callers with no options continue to work unchanged.
5260
func AsMain(input any, opts ...Option) error {
5361
// Apply options to build configuration.
@@ -57,10 +65,13 @@ func AsMain(input any, opts ...Option) error {
5765
}
5866

5967
// Check for --help and --doc flags before reading STDIN.
68+
// --help always takes precedence over --doc regardless of argument order.
6069
for _, arg := range os.Args[1:] {
6170
if arg == "--help" {
6271
return handleHelp(&cfg)
6372
}
73+
}
74+
for _, arg := range os.Args[1:] {
6475
if arg == "--doc" {
6576
return handleDoc(&cfg)
6677
}

go/fn/run_filemode_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package fn
1717
import (
1818
"os"
1919
"path/filepath"
20-
"strings"
2120
"testing"
2221

2322
"github.com/stretchr/testify/assert"
@@ -423,6 +422,6 @@ func TestFileMode_NonExistentAmongValid(t *testing.T) {
423422
err := AsMain(noopProcessor)
424423
require.Error(t, err)
425424
assert.Contains(t, err.Error(), "file not found")
426-
assert.Contains(t, err.Error(), strings.TrimPrefix(nonExistent, ""))
425+
assert.Contains(t, err.Error(), nonExistent)
427426
})
428427
}

0 commit comments

Comments
 (0)