MCPcopy Create free account
hub / github.com/Facets-cloud/flow / cmdEdit

Function cmdEdit

internal/app/edit.go:15–101  ·  view source on GitHub ↗

cmdEdit opens a brief.md in $EDITOR for either a task or a project. Per spec §5.5. Bumps updated_at after a clean editor exit.

(args []string)

Source from the content-addressed store, hash-verified

13// cmdEdit opens a brief.md in $EDITOR for either a task or a project.
14// Per spec §5.5. Bumps updated_at after a clean editor exit.
15func cmdEdit(args []string) int {
16 fs := flagSet("edit")
17 if err := fs.Parse(args); err != nil {
18 return 2
19 }
20 if fs.NArg() == 0 {
21 fmt.Fprintln(os.Stderr, "error: edit requires a ref")
22 return 2
23 }
24 ref := fs.Arg(0)
25
26 dbPath, err := flowDBPath()
27 if err != nil {
28 fmt.Fprintf(os.Stderr, "error: %v\n", err)
29 return 1
30 }
31 db, err := flowdb.OpenDB(dbPath)
32 if err != nil {
33 fmt.Fprintf(os.Stderr, "error: open db: %v\n", err)
34 return 1
35 }
36 defer db.Close()
37
38 kind, slug, err := resolveEditRef(db, ref)
39 if err != nil {
40 fmt.Fprintf(os.Stderr, "error: %v\n", err)
41 return 1
42 }
43
44 root, err := flowRoot()
45 if err != nil {
46 fmt.Fprintf(os.Stderr, "error: %v\n", err)
47 return 1
48 }
49
50 var briefPath string
51 switch kind {
52 case "task":
53 briefPath = filepath.Join(root, "tasks", slug, "brief.md")
54 case "project":
55 briefPath = filepath.Join(root, "projects", slug, "brief.md")
56 case "playbook":
57 briefPath = filepath.Join(root, "playbooks", slug, "brief.md")
58 }
59
60 // Ensure the parent directory exists so the editor doesn't refuse.
61 if err := os.MkdirAll(filepath.Dir(briefPath), 0o755); err != nil {
62 fmt.Fprintf(os.Stderr, "error: mkdir %s: %v\n", filepath.Dir(briefPath), err)
63 return 1
64 }
65
66 editor := os.Getenv("EDITOR")
67 if editor == "" {
68 editor = "vi"
69 }
70
71 // Accept EDITOR values that contain flags ("emacs -nw"), splitting on
72 // whitespace. This matches the convention of git and other tools.

Callers 10

TestCmdEditUnknownRefFunction · 0.85
TestCmdEditMissingRefFunction · 0.85
TestCmdEditPlaybookFunction · 0.85
RunFunction · 0.85

Calls 6

OpenDBFunction · 0.92
NowISOFunction · 0.92
flagSetFunction · 0.85
flowDBPathFunction · 0.85
resolveEditRefFunction · 0.85
flowRootFunction · 0.85