Files
agent-lib/internal/cli/status.go
T

47 lines
1.4 KiB
Go
Raw Permalink Normal View History

package cli
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/m3tam3re/agent-lib/internal/client"
)
func newStatusCmd() *cobra.Command {
var configPath, repoURL, ref string
var asJSON bool
cmd := &cobra.Command{
Use: "status",
Short: "Report deployed revision, pending changes, skips and unrecognized items",
Long: "Read-only local state report. Exits non-zero when local modifications " +
"block repository updates — suitable for headless drift checks. " +
"agent-lib version is included in the report.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
opts := client.SyncOptions{ConfigPath: configPath, RepoURL: repoURL, Ref: ref}
report, err := client.Status(opts)
if err != nil {
return fmt.Errorf("status: %w", err)
}
if asJSON {
if err := emitJSON(cmd, report); err != nil {
return err
}
} else {
client.PrintStatus(cmd.OutOrStdout(), report)
}
if report.Drift {
os.Exit(1)
}
return nil
},
}
cmd.Flags().StringVar(&configPath, "config", "", "client config path (default: "+client.ConfigEnv+" env, user config, or platform default)")
cmd.Flags().StringVar(&repoURL, "repo", "", "work repository URL or path — overrides any config, works without one")
cmd.Flags().StringVar(&ref, "ref", "", "branch or tag to pull (requires --repo)")
cmd.Flags().BoolVar(&asJSON, "json", false, "machine-readable output")
return cmd
}