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

Function cmdWorkdirList

internal/app/workdir.go:59–116  ·  view source on GitHub ↗

cmdWorkdirList prints all registered workdirs sorted by last_used_at descending (NULLs last). Each row is rendered across two output lines when a description is present — header first, description on a second indented line — so descriptions don't force the header columns wide.

(args []string)

Source from the content-addressed store, hash-verified

57// when a description is present — header first, description on a second
58// indented line — so descriptions don't force the header columns wide.
59func cmdWorkdirList(args []string) int {
60 fs := flagSet("workdir list")
61 if err := fs.Parse(args); err != nil {
62 return 2
63 }
64 if fs.NArg() > 0 {
65 fmt.Fprintln(os.Stderr, "error: workdir list takes no positional arguments")
66 return 2
67 }
68 db, rc := openFlowDBForWorkdir()
69 if rc != 0 {
70 return rc
71 }
72 defer db.Close()
73
74 list, err := flowdb.ListWorkdirs(db)
75 if err != nil {
76 fmt.Fprintf(os.Stderr, "error: %v\n", err)
77 return 1
78 }
79 if len(list) == 0 {
80 fmt.Println("(no registered workdirs)")
81 return 0
82 }
83
84 maxPath := 0
85 maxName := 0
86 for _, w := range list {
87 if n := len(w.Path); n > maxPath {
88 maxPath = n
89 }
90 if w.Name.Valid {
91 if n := len(w.Name.String); n > maxName {
92 maxName = n
93 }
94 }
95 }
96 now := time.Now()
97 for _, w := range list {
98 parts := []string{fmt.Sprintf(" %-*s", maxPath, w.Path)}
99 if maxName > 0 {
100 name := ""
101 if w.Name.Valid {
102 name = w.Name.String
103 }
104 parts = append(parts, fmt.Sprintf("%-*s", maxName, name))
105 }
106 if w.GitRemote.Valid && w.GitRemote.String != "" {
107 parts = append(parts, "origin: "+w.GitRemote.String)
108 }
109 parts = append(parts, humanizeLastUsed(w.LastUsedAt, now))
110 fmt.Println(strings.Join(parts, " "))
111 if w.Description.Valid && w.Description.String != "" {
112 fmt.Printf(" %s\n", w.Description.String)
113 }
114 }
115 return 0
116}

Callers 1

cmdWorkdirFunction · 0.85

Calls 4

ListWorkdirsFunction · 0.92
flagSetFunction · 0.85
openFlowDBForWorkdirFunction · 0.85
humanizeLastUsedFunction · 0.85

Tested by

no test coverage detected