Add caller to test Call Methods

pull/2/merge
rwxrob 3 years ago
parent add9829c5d
commit 3aa6c71e55
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -11,10 +11,10 @@ import (
) )
// Method defines the main code to execute for a command (Cmd). By // Method defines the main code to execute for a command (Cmd). By
// convention the parameter list should be names "args" if there are // convention the parameter list should be named "args" if there are
// args expected and "none" if not. Methods must never write error // args expected and underscore (_) if not. Methods must never write
// output to anything but standard error and should almost always use // error output to anything but standard error and should almost always
// the log package to do so. // use the log package to do so.
type Method func(caller *Cmd, args ...string) error type Method func(caller *Cmd, args ...string) error
// ----------------------- errors, exit, debug ----------------------- // ----------------------- errors, exit, debug -----------------------

@ -15,7 +15,7 @@ func ExampleCmd_Seek() {
hello := &bonzai.Cmd{ hello := &bonzai.Cmd{
Name: `hello`, Name: `hello`,
Params: []string{"there"}, Params: []string{"there"},
Call: func(args ...string) error { Call: func(_ *bonzai.Cmd, args ...string) error {
if len(args) > 0 { if len(args) > 0 {
fmt.Printf("hello %v\n", args[0]) fmt.Printf("hello %v\n", args[0])
return nil return nil
@ -28,7 +28,7 @@ func ExampleCmd_Seek() {
hi := &bonzai.Cmd{ hi := &bonzai.Cmd{
Name: `hi`, Name: `hi`,
Params: []string{"there", "ya"}, Params: []string{"there", "ya"},
Call: func(args ...string) error { Call: func(_ *bonzai.Cmd, args ...string) error {
if len(args) > 0 { if len(args) > 0 {
fmt.Printf("hi %v\n", args[0]) fmt.Printf("hi %v\n", args[0])
return nil return nil
@ -40,7 +40,7 @@ func ExampleCmd_Seek() {
yo := &bonzai.Cmd{ yo := &bonzai.Cmd{
Name: `yo`, Name: `yo`,
Call: func(args ...string) error { Call: func(_ *bonzai.Cmd, args ...string) error {
fmt.Println("yo") fmt.Println("yo")
return nil return nil
}, },
@ -49,7 +49,7 @@ func ExampleCmd_Seek() {
salut := &bonzai.Cmd{ salut := &bonzai.Cmd{
Name: `salut`, Name: `salut`,
Params: []string{"la"}, Params: []string{"la"},
Call: func(args ...string) error { Call: func(_ *bonzai.Cmd, args ...string) error {
if len(args) > 0 { if len(args) > 0 {
fmt.Printf("salut %v\n", args[0]) fmt.Printf("salut %v\n", args[0])
return nil return nil

Loading…
Cancel
Save