package cmd import ( "fmt" "io" "os" "path/filepath" "github.com/spf13/cobra" "github.com/warrenronsiek/ctask/internal/config" ) var notesCmd = &cobra.Command{ Use: "notes ", Short: "Print a workspace's notes.md to stdout", Args: cobra.ExactArgs(1), SilenceUsage: true, SilenceErrors: true, RunE: runNotes, } func init() { notesCmd.ValidArgsFunction = completeWorkspaces(completionAny) rootCmd.AddCommand(notesCmd) } // runNotes streams /notes.md to stdout. SilenceErrors is enabled // so the [ctask]-prefixed message we print to stderr is the only diagnostic // the user sees — no Cobra "Error: ..." line on top of it. func runNotes(cmd *cobra.Command, args []string) error { roots := config.SearchRoots() ws := resolveOne(roots, args[0], true) notesPath := filepath.Join(ws.Path, "notes.md") f, err := os.Open(notesPath) if err != nil { if os.IsNotExist(err) { fmt.Fprintf(os.Stderr, "[ctask] no notes.md found in workspace %q\n", args[0]) return fmt.Errorf("notes.md missing") } fmt.Fprintf(os.Stderr, "[ctask] error reading notes.md: %v\n", err) return err } defer f.Close() if _, err := io.Copy(os.Stdout, f); err != nil { fmt.Fprintf(os.Stderr, "[ctask] error streaming notes.md: %v\n", err) return err } return nil }