fix: update Cli doc comment + tests for new Options contract
Cli struct unchanged — already conforms. Tests use WithOption() convenience. 9 tests passing. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
d8fb18a663
commit
416e975fbb
2 changed files with 9 additions and 14 deletions
9
cli.go
9
cli.go
|
|
@ -3,14 +3,9 @@
|
|||
// Cli is the CLI surface layer for the Core command tree.
|
||||
// It reads commands from Core's registry and wires them to terminal I/O.
|
||||
//
|
||||
// Run the CLI:
|
||||
//
|
||||
// c := core.New(core.Options{{Key: "name", Value: "myapp"}})
|
||||
// c.Command("deploy", handler)
|
||||
// c := core.New(core.WithOption("name", "myapp")).Value.(*Core)
|
||||
// c.Command("deploy", core.Command{Action: handler})
|
||||
// c.Cli().Run()
|
||||
//
|
||||
// The Cli resolves os.Args to a command path, parses flags,
|
||||
// and calls the command's action with parsed options.
|
||||
package core
|
||||
|
||||
import (
|
||||
|
|
|
|||
14
cli_test.go
14
cli_test.go
|
|
@ -16,7 +16,7 @@ func TestCli_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCli_Banner_Good(t *testing.T) {
|
||||
c := New(WithOptions(NewOptions(Option{Key: "name", Value: "myapp"}))).Value.(*Core)
|
||||
c := New(WithOption("name", "myapp")).Value.(*Core)
|
||||
assert.Equal(t, "myapp", c.Cli().Banner())
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ func TestCli_Run_Good(t *testing.T) {
|
|||
c.Command("hello", Command{Action: func(_ Options) Result {
|
||||
executed = true
|
||||
return Result{Value: "world", OK: true}
|
||||
}))
|
||||
}})
|
||||
r := c.Cli().Run("hello")
|
||||
assert.True(t, r.OK)
|
||||
assert.Equal(t, "world", r.Value)
|
||||
|
|
@ -45,7 +45,7 @@ func TestCli_Run_Nested_Good(t *testing.T) {
|
|||
c.Command("deploy/to/homelab", Command{Action: func(_ Options) Result {
|
||||
executed = true
|
||||
return Result{OK: true}
|
||||
}))
|
||||
}})
|
||||
r := c.Cli().Run("deploy", "to", "homelab")
|
||||
assert.True(t, r.OK)
|
||||
assert.True(t, executed)
|
||||
|
|
@ -57,7 +57,7 @@ func TestCli_Run_WithFlags_Good(t *testing.T) {
|
|||
c.Command("serve", Command{Action: func(opts Options) Result {
|
||||
received = opts
|
||||
return Result{OK: true}
|
||||
}))
|
||||
}})
|
||||
c.Cli().Run("serve", "--port=8080", "--debug")
|
||||
assert.Equal(t, "8080", received.String("port"))
|
||||
assert.True(t, received.Bool("debug"))
|
||||
|
|
@ -70,9 +70,9 @@ func TestCli_Run_NoCommand_Good(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCli_PrintHelp_Good(t *testing.T) {
|
||||
c := New(WithOptions(NewOptions(Option{Key: "name", Value: "myapp"}))).Value.(*Core)
|
||||
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }))
|
||||
c.Command("serve", Command{Action: func(_ Options) Result { return Result{OK: true} }))
|
||||
c := New(WithOption("name", "myapp")).Value.(*Core)
|
||||
c.Command("deploy", Command{Action: func(_ Options) Result { return Result{OK: true} }})
|
||||
c.Command("serve", Command{Action: func(_ Options) Result { return Result{OK: true} }})
|
||||
c.Cli().PrintHelp()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue