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.
z/go.go

62 lines
1.2 KiB
Go

package main
import (
"fmt"
"log"
"os"
"strings"
Z "github.com/rwxrob/bonzai"
"github.com/rwxrob/bonzai/inc/help"
"github.com/rwxrob/fs/file"
)
var golang = &Z.Cmd{
Name: `go`,
Summary: `go related helper actions`,
Aliases: []string{"rust"},
MinArgs: 1,
Commands: []*Z.Cmd{help.Cmd, gowork, genisrune},
}
var gowork = &Z.Cmd{
Name: `work`,
Summary: `turn on or off go.work file`,
Usage: `(on|off)`,
MinArgs: 1,
Params: []string{"on", "off"},
Commands: []*Z.Cmd{help.Cmd},
Call: func(x *Z.Cmd, args ...string) error {
switch args[0] {
case "on":
if file.Exists("go.work.off") {
log.Print("go.work.off -> go.work")
return os.Rename("go.work.off", "go.work")
}
case "off":
if file.Exists("go.work") {
log.Print("go.work -> go.work.off")
return os.Rename("go.work", "go.work.off")
}
default:
return x.UsageError()
}
return nil
},
}
var genisrune = &Z.Cmd{
Name: `genisrune`,
Summary: `generate a performant rune check condition`,
Commands: []*Z.Cmd{help.Cmd},
MinArgs: 1,
Call: func(x *Z.Cmd, args ...string) error {
var conds []string
for _, r := range args[0] {
conds = append(conds, fmt.Sprintf("r==%q", r))
}
fmt.Println(strings.Join(conds, "||"))
return nil
},
}