Completes the infra-loop verb surface. work start creates .worktrees/<topic> on <user>/<topic> off <remote>/master (git-crypt-aware, ensures .worktrees is ignored) and prints the path for native EnterWorktree entry. work land fetches, merges master in, verifies, pushes HEAD:master with non-fast-forward retry, and falls back to pushing the feature branch for a PR when the direct push is rejected (branch protection). work clean removes the worktree + branch. Safety: work land REFUSES to push when it cannot verify (no --verify-cmd and no auto-detected suite) unless --no-verify is passed. This was added after an accidental smoke-test invocation pushed unverified WIP to master (benign — the infra CI applied 0 stacks since the diff was cli/-only — but the gate makes an unverified land a deliberate choice, not the default). Known v0.1 limitation: land does not yet block on CI to green; that arrives with the ci/deploy watch verbs. It prints a reminder to follow the pipeline manually. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// version is stamped at build time via -ldflags "-X main.version=vX.Y.Z".
|
|
var version = "dev"
|
|
|
|
// buildRegistry returns every homelab verb. New verb-groups append here.
|
|
func buildRegistry() []Command {
|
|
var reg []Command
|
|
reg = append(reg, claimCommands()...)
|
|
reg = append(reg, tfCommands()...)
|
|
reg = append(reg, workCommands()...)
|
|
return reg
|
|
}
|
|
|
|
// dispatchTop handles the homelab verb surface. handled=false means the args are
|
|
// not a homelab verb, so main() falls back to the legacy -use-case path.
|
|
func dispatchTop(args []string) (handled bool, err error) {
|
|
if len(args) == 0 {
|
|
fmt.Print(usage())
|
|
return true, nil
|
|
}
|
|
switch args[0] {
|
|
case "help", "-h", "--help":
|
|
fmt.Print(usage())
|
|
return true, nil
|
|
case "version", "--version":
|
|
fmt.Println("homelab " + version)
|
|
return true, nil
|
|
case "manifest":
|
|
reg := buildRegistry()
|
|
if containsArg(args[1:], "--json") {
|
|
out, err := manifestJSON(reg)
|
|
if err != nil {
|
|
return true, err
|
|
}
|
|
fmt.Println(out)
|
|
return true, nil
|
|
}
|
|
fmt.Print(manifestText(reg))
|
|
return true, nil
|
|
}
|
|
if strings.HasPrefix(args[0], "-") {
|
|
return false, nil
|
|
}
|
|
reg := buildRegistry()
|
|
if !isCommandGroup(reg, args[0]) {
|
|
return false, nil
|
|
}
|
|
return true, dispatch(reg, args)
|
|
}
|
|
|
|
func isCommandGroup(reg []Command, group string) bool {
|
|
for _, c := range reg {
|
|
if len(c.Path) > 0 && c.Path[0] == group {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func containsArg(args []string, want string) bool {
|
|
for _, a := range args {
|
|
if a == want {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func usage() string {
|
|
var b strings.Builder
|
|
fmt.Fprintf(&b, "homelab %s — unified homelab operations CLI\n\n", version)
|
|
b.WriteString("Usage:\n homelab <command> [args]\n\nCommands:\n")
|
|
for _, line := range strings.Split(strings.TrimRight(manifestText(buildRegistry()), "\n"), "\n") {
|
|
if line != "" {
|
|
b.WriteString(" " + line + "\n")
|
|
}
|
|
}
|
|
b.WriteString("\n manifest [--json] list all commands (machine-readable with --json)\n")
|
|
b.WriteString(" version print version\n")
|
|
b.WriteString("\nLegacy webhook use-cases remain available via -use-case=<name>.\n")
|
|
return b.String()
|
|
}
|