mirror of https://github.com/rwxrob/bonzai
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
886 B
Go
44 lines
886 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/rwxrob/bonzai/help"
|
|
Z "github.com/rwxrob/bonzai/z"
|
|
"github.com/rwxrob/term"
|
|
)
|
|
|
|
func main() {
|
|
Cmd.Run()
|
|
}
|
|
|
|
var Cmd = &Z.Cmd{
|
|
Name: `bonzai`,
|
|
Summary: `bonzai command tree utility`,
|
|
Version: `v0.0.1`,
|
|
Copyright: `Copyright 2021 Robert S Muhlestein`,
|
|
License: `Apache-2.0`,
|
|
Commands: []*Z.Cmd{help.Cmd, sh2slice},
|
|
}
|
|
|
|
var sh2slice = &Z.Cmd{
|
|
Name: `sh2slice`,
|
|
Summary: `splits a shell command into arguments`,
|
|
Commands: []*Z.Cmd{help.Cmd},
|
|
Call: func(_ *Z.Cmd, args ...string) error {
|
|
list := []string{}
|
|
if len(args) == 0 {
|
|
args = append(args, term.Read())
|
|
}
|
|
for _, a := range args {
|
|
// FIXME add awareness or globs and quoted segments
|
|
for _, aa := range strings.Fields(a) {
|
|
list = append(list, fmt.Sprintf("%q", aa))
|
|
}
|
|
}
|
|
fmt.Println(strings.Join(list, ","))
|
|
return nil
|
|
},
|
|
}
|