// Command corestack-docs creates and checks ADR and plan records. See docs/docs-format.md. package main import ( "flag" "fmt" "io" "os" "time" "go.auvem.com/corestack/internal/docs" ) const usage = `usage: corestack-docs new adr|plan "Title" corestack-docs check [--root DIR] ` func main() { os.Exit(run(os.Args[1:], os.Stdout, os.Stderr, time.Now())) } // run returns the exit status: 0 success, 1 problems or failure, 2 usage error. func run(args []string, stdout, stderr io.Writer, now time.Time) int { if len(args) == 0 { fmt.Fprint(stderr, usage) return 2 } switch args[0] { case "new": if len(args) != 3 || (args[1] != "adr" && args[1] != "plan") { fmt.Fprint(stderr, usage) return 2 } path, err := docs.New(".", args[1], args[2], now) if err != nil { fmt.Fprintf(stderr, "corestack-docs: %v\n", err) return 1 } fmt.Fprintln(stdout, path) return 0 case "check": fs := flag.NewFlagSet("corestack-docs check", flag.ContinueOnError) fs.SetOutput(stderr) root := fs.String("root", ".", "repository root") if err := fs.Parse(args[1:]); err != nil || fs.NArg() != 0 { if fs.NArg() != 0 { fmt.Fprint(stderr, usage) } return 2 } res, err := docs.Check(*root) if err != nil { fmt.Fprintf(stderr, "corestack-docs: %v\n", err) return 1 } for _, p := range res.Problems { fmt.Fprintln(stdout, p) } if len(res.Problems) > 0 { return 1 } fmt.Fprintf(stdout, "ok: %d records checked\n", res.Records) return 0 } fmt.Fprint(stderr, usage) return 2 }