feat(P01): CLI skeleton with Cobra, subcommand stubs, pre-push hook
Implements Phase 1 of v0.1 Foundation:
- go.mod with Go 1.25
- cmd/orca/main.go entry point
- internal/cli/root.go with global --json flag
- internal/cli/version.go (orca version)
- internal/cli/init.go (orca init - creates ~/.orca/)
- internal/cli/status.go (orca status - shows daemon info)
- internal/cli/node.go (orca node {join,leave,list} - stubs)
- internal/cli/job.go (orca job {run,list,stop,logs} - stubs)
- Makefile (build, test, lint, fmt, release)
- LICENSE (MIT)
- README.md with quickstart
- .gitignore
- .githooks/pre-push + scripts/trigger_coreci.sh (CoreCI trigger)
- Smoke tests in internal/cli/root_test.go
Verified: go build, go test, go vet, gofmt all pass.
---ci---
project: orca
phase: 1
milestone: v0.1
status: execute
req_covered:
- REQ-001
- REQ-002
- REQ-013
- REQ-015
- REQ-016
- REQ-019
- REQ-024
---/ci---
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Initialize local orca state directory",
|
||||
Long: "Create the local orca state directory at ~/.orca/ and write a default config file.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("get home dir: %w", err)
|
||||
}
|
||||
orcaDir := filepath.Join(home, ".orca")
|
||||
if err := os.MkdirAll(orcaDir, 0o755); err != nil {
|
||||
return fmt.Errorf("create orca dir: %w", err)
|
||||
}
|
||||
result := map[string]string{
|
||||
"path": orcaDir,
|
||||
"status": "initialized",
|
||||
}
|
||||
if jsonOutput {
|
||||
return printJSON(result)
|
||||
}
|
||||
printText("✓ Initialized orca state at %s\n", orcaDir)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(initCmd)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var jobCmd = &cobra.Command{
|
||||
Use: "job",
|
||||
Short: "Manage orca jobs",
|
||||
Long: "Run, list, stop, and inspect orca jobs.",
|
||||
}
|
||||
|
||||
var jobRunCmd = &cobra.Command{
|
||||
Use: "run <spec.hcl>",
|
||||
Short: "Run a job from an HCL spec file",
|
||||
Long: "Submit a job spec and execute it. Implemented in Phase 3.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca job run " + args[0])
|
||||
},
|
||||
}
|
||||
|
||||
var jobListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all jobs",
|
||||
Long: "Display all jobs and their status. Implemented in Phase 3.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca job list")
|
||||
},
|
||||
}
|
||||
|
||||
var jobStopCmd = &cobra.Command{
|
||||
Use: "stop <job-id>",
|
||||
Short: "Stop a running job",
|
||||
Long: "Stop a job by ID. Implemented in Phase 3.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca job stop " + args[0])
|
||||
},
|
||||
}
|
||||
|
||||
var jobLogsCmd = &cobra.Command{
|
||||
Use: "logs <job-id>",
|
||||
Short: "Show logs for a job",
|
||||
Long: "Display the logs for a job by ID. Implemented in Phase 3.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca job logs " + args[0])
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
jobCmd.AddCommand(jobRunCmd)
|
||||
jobCmd.AddCommand(jobListCmd)
|
||||
jobCmd.AddCommand(jobStopCmd)
|
||||
jobCmd.AddCommand(jobLogsCmd)
|
||||
rootCmd.AddCommand(jobCmd)
|
||||
}
|
||||
|
||||
func notImplemented(cmd string) error {
|
||||
if jsonOutput {
|
||||
return printJSON(map[string]any{
|
||||
"command": cmd,
|
||||
"status": "not_implemented",
|
||||
"phase": "1-cli-skeleton",
|
||||
"next": "Phase 2-6 will implement this",
|
||||
})
|
||||
}
|
||||
fmt.Fprintf(rootCmd.ErrOrStderr(), "✗ %s: not yet implemented (Phase 1: CLI skeleton only)\n", cmd)
|
||||
fmt.Fprintf(rootCmd.ErrOrStderr(), " see .ciagent/ROADMAP.md for the full 6-phase plan\n")
|
||||
return fmt.Errorf("not implemented: %s", cmd)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var nodeCmd = &cobra.Command{
|
||||
Use: "node",
|
||||
Short: "Manage orca nodes",
|
||||
Long: "Join, leave, or list orca nodes in the cluster.",
|
||||
}
|
||||
|
||||
var nodeJoinCmd = &cobra.Command{
|
||||
Use: "join",
|
||||
Short: "Join a node to the orca cluster",
|
||||
Long: "Register the local node with the orca cluster. Implemented in Phase 2.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca node join")
|
||||
},
|
||||
}
|
||||
|
||||
var nodeLeaveCmd = &cobra.Command{
|
||||
Use: "leave",
|
||||
Short: "Remove a node from the orca cluster",
|
||||
Long: "Deregister a node from the orca cluster. Implemented in Phase 2.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca node leave")
|
||||
},
|
||||
}
|
||||
|
||||
var nodeListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all nodes in the orca cluster",
|
||||
Long: "Display all registered nodes. Implemented in Phase 2.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return notImplemented("orca node list")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
nodeCmd.AddCommand(nodeJoinCmd)
|
||||
nodeCmd.AddCommand(nodeLeaveCmd)
|
||||
nodeCmd.AddCommand(nodeListCmd)
|
||||
rootCmd.AddCommand(nodeCmd)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "0.1.0-dev"
|
||||
gitCommit = "unknown"
|
||||
buildTime = "unknown"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "orca",
|
||||
Short: "Orca — offline/CLI-first orchestration engine",
|
||||
Long: `Orca is a minimalist, offline-first, CLI-first orchestration engine
|
||||
inspired by HashiCorp Nomad, prioritizing stability, security, and simplicity
|
||||
over feature richness.`,
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
}
|
||||
|
||||
var jsonOutput bool
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "output in JSON format")
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func printJSON(v any) error {
|
||||
enc := json.NewEncoder(rootCmd.OutOrStdout())
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(v)
|
||||
}
|
||||
|
||||
func printText(format string, args ...any) {
|
||||
fmt.Fprintf(rootCmd.OutOrStdout(), format, args...)
|
||||
}
|
||||
|
||||
func printResult(text string, jsonObj any) {
|
||||
if jsonOutput {
|
||||
_ = printJSON(jsonObj)
|
||||
return
|
||||
}
|
||||
printText("%s\n", text)
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVersionCommandExists(t *testing.T) {
|
||||
found := false
|
||||
for _, cmd := range rootCmd.Commands() {
|
||||
if cmd.Name() == "version" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("version command not registered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRootHasAllSubcommands(t *testing.T) {
|
||||
expected := []string{"version", "init", "status", "node", "job"}
|
||||
registered := make(map[string]bool)
|
||||
for _, cmd := range rootCmd.Commands() {
|
||||
registered[cmd.Name()] = true
|
||||
}
|
||||
for _, name := range expected {
|
||||
if !registered[name] {
|
||||
t.Errorf("expected subcommand %q not registered", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeSubcommands(t *testing.T) {
|
||||
expected := []string{"join", "leave", "list"}
|
||||
registered := make(map[string]bool)
|
||||
for _, cmd := range nodeCmd.Commands() {
|
||||
registered[cmd.Name()] = true
|
||||
}
|
||||
for _, name := range expected {
|
||||
if !registered[name] {
|
||||
t.Errorf("expected node subcommand %q not registered", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobSubcommands(t *testing.T) {
|
||||
expected := []string{"run", "list", "stop", "logs"}
|
||||
registered := make(map[string]bool)
|
||||
for _, cmd := range jobCmd.Commands() {
|
||||
registered[cmd.Name()] = true
|
||||
}
|
||||
for _, name := range expected {
|
||||
if !registered[name] {
|
||||
t.Errorf("expected job subcommand %q not registered", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRootHelpMentionsKeyPillars(t *testing.T) {
|
||||
help := rootCmd.Long
|
||||
for _, pillar := range []string{"offline", "CLI", "Nomad", "simplicity"} {
|
||||
if !strings.Contains(strings.ToLower(help), strings.ToLower(pillar)) {
|
||||
t.Errorf("root help does not mention pillar %q", pillar)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var statusCmd = &cobra.Command{
|
||||
Use: "status",
|
||||
Short: "Show orca daemon status",
|
||||
Long: "Display the current status of the local orca daemon, including version, uptime, and connection info.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
status := map[string]any{
|
||||
"version": version,
|
||||
"daemon": "stopped",
|
||||
"uptime": "0s",
|
||||
"api_addr": "https://localhost:8443",
|
||||
"health": "unknown",
|
||||
"phase": "1-cli-skeleton",
|
||||
"milestone": "v0.1",
|
||||
}
|
||||
if jsonOutput {
|
||||
return printJSON(status)
|
||||
}
|
||||
printText("orca daemon status\n")
|
||||
printText(" version: %s\n", version)
|
||||
printText(" daemon: %s\n", "stopped (daemon not yet implemented in Phase 1)")
|
||||
printText(" api_addr: %s\n", "https://localhost:8443")
|
||||
printText(" phase: %s\n", "1-cli-skeleton")
|
||||
printText(" milestone: %s\n", "v0.1")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(statusCmd)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print version information",
|
||||
Long: "Print the orca version, git commit, and build time.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
info := map[string]string{
|
||||
"version": version,
|
||||
"git_commit": gitCommit,
|
||||
"build_time": buildTime,
|
||||
}
|
||||
if jsonOutput {
|
||||
return printJSON(info)
|
||||
}
|
||||
printText("orca version %s\n", version)
|
||||
printText(" git commit: %s\n", gitCommit)
|
||||
printText(" build time: %s\n", buildTime)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user