mirror of https://github.com/rwxrob/z
Add initial commands
parent
57b5b6da4a
commit
d41c4b0638
@ -1,82 +0,0 @@
|
||||
package foo
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/rwxrob/bonzai"
|
||||
"github.com/rwxrob/bonzai/comp"
|
||||
"github.com/rwxrob/bonzai/inc/help"
|
||||
)
|
||||
|
||||
var Cmd = &bonzai.Cmd{
|
||||
|
||||
Name: `foo`,
|
||||
Summary: `just a sample foo command`,
|
||||
Usage: `[B|bar|own|h|help]`,
|
||||
Version: `v0.0.1`,
|
||||
Copyright: `Copyright 2021 Robert S Muhlestein`,
|
||||
License: `Apache-2.0`,
|
||||
Commands: []*bonzai.Cmd{help.Cmd, Bar, own},
|
||||
|
||||
Description: `
|
||||
The foo commands do foo stuff. You can start the description here
|
||||
and wrap it to look nice and it will just work. Descriptions are
|
||||
written in BonzaiMark™, a simplification of CommonMark that that
|
||||
mostly follows Go documentation guidelines`,
|
||||
|
||||
Other: map[string]string{
|
||||
`foo`: `something about foo`,
|
||||
`another`: `something about another command`,
|
||||
},
|
||||
|
||||
// no Call since has Commands, if had Call would only call if
|
||||
// commands didn't match
|
||||
}
|
||||
|
||||
// Commands can be grouped into the same file or separately, public or
|
||||
// private. Public let's others compose specific subcommands (foo.Bar),
|
||||
// private just keeps it composed and only available within this Bonzai
|
||||
// command.
|
||||
|
||||
// Aliases are not commands but will be replaced by their target names.
|
||||
|
||||
var Bar = &bonzai.Cmd{
|
||||
Name: `bar`,
|
||||
Aliases: []string{"B", "notbar"}, // to make a point
|
||||
Commands: []*bonzai.Cmd{help.Cmd, file},
|
||||
|
||||
// Call first-class functions can be highly detailed, refer to an
|
||||
// existing function someplace else, or can call high-level package
|
||||
// library functions. Developers are encouraged to consider well where
|
||||
// they maintain the core logic of their applications. Often, it will
|
||||
// not be here within the bonzai.Cmd definition. One use case for
|
||||
// decoupled first-class Call functions is when creating multiple
|
||||
// binaries for different target languages. In such cases this
|
||||
// bonzai.Cmd definition is essentially just a wrapper for
|
||||
// documentation and other language-specific embedded assets.
|
||||
|
||||
Call: func(_ *bonzai.Cmd, _ ...string) error { // note conventional _
|
||||
log.Printf("would bar stuff")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// Different completion methods are be set including the expected
|
||||
// standard ones from bash and other shells. Not that these completion
|
||||
// methods only work if the shell supports completion (including
|
||||
// the Bonzai Shell, which can be set as the default Cmd to provide rich
|
||||
// shell interactivity where normally no shell is available, such as in
|
||||
// FROM SCRATCH containers that use a Bonzai tree as the core binary).
|
||||
|
||||
var file = &bonzai.Cmd{
|
||||
Name: `file`,
|
||||
Commands: []*bonzai.Cmd{help.Cmd},
|
||||
Completer: comp.File,
|
||||
Call: func(x *bonzai.Cmd, args ...string) error {
|
||||
if len(args) == 0 {
|
||||
return x.UsageError()
|
||||
}
|
||||
log.Printf("would show file information about %v", args[0])
|
||||
return nil
|
||||
},
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package main
|
||||
|
||||
import "github.com/rwxrob/foo"
|
||||
|
||||
func main() { foo.Cmd.Run() }
|
@ -1,32 +0,0 @@
|
||||
package foo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Unlike other Go projects, Bonzai commands don't really benefit from
|
||||
// Go's example-based tests (which normally would be in package
|
||||
// foo_test). Instead, testing should be against the first-class Call
|
||||
// functions directly (with nil callers) or the high-level functions
|
||||
// from a package library into which they call themselves (which might
|
||||
// have their own example and other tests).
|
||||
|
||||
func TestBar(t *testing.T) {
|
||||
|
||||
// capture the output
|
||||
buf := new(bytes.Buffer)
|
||||
log.SetFlags(0)
|
||||
log.SetOutput(buf)
|
||||
defer log.SetFlags(log.Flags())
|
||||
defer log.SetOutput(os.Stderr)
|
||||
|
||||
Bar.Call(nil)
|
||||
|
||||
t.Log(buf)
|
||||
if buf.String() != "would bar stuff\n" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
@ -1,3 +1,21 @@
|
||||
module github.com/rwxrob/bonzai-foo
|
||||
module github.com/rwxrob/z
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/rwxrob/bonzai v0.0.19
|
||||
github.com/rwxrob/yaml2json v0.1.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/rwxrob/fn v0.1.0 // indirect
|
||||
github.com/rwxrob/fs v0.2.0 // indirect
|
||||
github.com/rwxrob/json v0.4.1 // indirect
|
||||
github.com/rwxrob/structs v0.5.0 // indirect
|
||||
github.com/rwxrob/term v0.1.2 // indirect
|
||||
github.com/rwxrob/to v0.2.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect
|
||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
@ -0,0 +1,25 @@
|
||||
github.com/rwxrob/bonzai v0.0.19 h1:GvSUifZqqnjhIAEDGHnq2v7xyJxHhoBa589zrJgiVYI=
|
||||
github.com/rwxrob/bonzai v0.0.19/go.mod h1:gkNuRMH3DrSpVR4OJBPxxxt26srZijD9a/Y9uc1p8Ko=
|
||||
github.com/rwxrob/fn v0.1.0 h1:vlQOPxZ77IlXSIDu2eIkuQgMtInlMNRHqwgKfkNAHAA=
|
||||
github.com/rwxrob/fn v0.1.0/go.mod h1:omPqOqEB+dDna09z5pi5YFxq4IZqDvv3wFPUCES5LvY=
|
||||
github.com/rwxrob/fs v0.2.0 h1:f0AO9BgsWlYGwiBJH7W60k3AJh0rGOtYZuozkUCQVRw=
|
||||
github.com/rwxrob/fs v0.2.0/go.mod h1:vO8AeluD7rnrO7zC54745xTEBFgHPUpHL0hbp1NnsVo=
|
||||
github.com/rwxrob/json v0.4.1 h1:b4ToZe4mrQO8rRL/kRFglzZszyZZnGv6JRHj6jrI3f4=
|
||||
github.com/rwxrob/json v0.4.1/go.mod h1:DU3TQKCWY4bK7sQ0wu80cRmTs96b6M//OYvT7Eg2mJA=
|
||||
github.com/rwxrob/structs v0.5.0 h1:pjLsfyYHS+gB1CtzRj3H39wRYL4lI5pTpFf8kl91guw=
|
||||
github.com/rwxrob/structs v0.5.0/go.mod h1:2gIte2ZI9zUok6q6F3v3l41ZXo7Zg5Kf1GUTP2+pXyQ=
|
||||
github.com/rwxrob/term v0.1.2 h1:w71H8seLUS/E5PKtg5VjSlEqv5xPXLYwwQ8FZ+zb3OA=
|
||||
github.com/rwxrob/term v0.1.2/go.mod h1:IVE7hG+VQlM4R+kS4pY6uhfMHoG0QECrZF7d7bKcdsk=
|
||||
github.com/rwxrob/to v0.2.1 h1:ZYBNEa8LJT5VDQUHm2wSwiRf61xSqU87UqbYvitV3eY=
|
||||
github.com/rwxrob/to v0.2.1/go.mod h1:8qdgCWkh50Avs8sRpV6/P7lAQgVf3KLRSKMZahV/W48=
|
||||
github.com/rwxrob/yaml2json v0.1.0 h1:9ZyxAHZaL1n88tmTDKddz/o2vx3j3ygPuUFfmV85BNs=
|
||||
github.com/rwxrob/yaml2json v0.1.0/go.mod h1:LZv0PcOqzj7q7afI3YRiPogmLHAdv579f/YM/6vcQrg=
|
||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s=
|
||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
|
||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
@ -1,19 +1,7 @@
|
||||
go 1.18
|
||||
|
||||
// Add relative paths to repos of things you don't want to `go get`
|
||||
// every time. Always include . or example tests requiring full
|
||||
// references to package imports will fail. Read go work -h for more.
|
||||
// Packages upon which bonzai depends have been included for convenience
|
||||
// but can be removed without worry by most.
|
||||
go 1.19
|
||||
|
||||
use (
|
||||
.
|
||||
../bonzai
|
||||
../fn
|
||||
../fs
|
||||
../json
|
||||
../scan
|
||||
../structs
|
||||
../term
|
||||
../to
|
||||
../yaml2json
|
||||
)
|
||||
|
@ -0,0 +1,12 @@
|
||||
github.com/rwxrob/to v0.1.1 h1:CTwNL00Vm9j3fCHSKVYQwGnV7r/DFZdmNhI7vA1ktQw=
|
||||
github.com/rwxrob/to v0.1.1/go.mod h1:8qdgCWkh50Avs8sRpV6/P7lAQgVf3KLRSKMZahV/W48=
|
||||
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 h1:syTAU9FwmvzEoIYMqcPHOcVm4H3U5u90WsvuYgwpETU=
|
||||
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rwxrob/bonzai"
|
||||
"github.com/rwxrob/bonzai/inc/help"
|
||||
"github.com/rwxrob/yaml2json"
|
||||
)
|
||||
|
||||
func main() {
|
||||
Cmd.Run()
|
||||
}
|
||||
|
||||
var Cmd = &bonzai.Cmd{
|
||||
Name: `z`,
|
||||
Summary: `rwxrob's bonzai command tree`,
|
||||
Version: `v0.0.1`,
|
||||
Copyright: `Copyright 2021 Robert S Muhlestein`,
|
||||
License: `Apache-2.0`,
|
||||
Commands: []*bonzai.Cmd{help.Cmd, yaml2json.Cmd},
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package foo
|
||||
|
||||
// Go treats all files as if they are, more or less, in the same large
|
||||
// file. Create separate files to help you and others find the code you
|
||||
// need quickly.
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
// if typing bonzai becomes tedious use capital Z as a convention
|
||||
|
||||
Z "github.com/rwxrob/bonzai"
|
||||
)
|
||||
|
||||
var own = &Z.Cmd{
|
||||
Name: `own`,
|
||||
Call: func(caller *Z.Cmd, none ...string) error {
|
||||
log.Print("I'm in my own file.")
|
||||
return nil
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue