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

Function cmdWorkdirAdd

internal/app/workdir.go:143–201  ·  view source on GitHub ↗

cmdWorkdirAdd registers (making it absolute), auto-detects git remote from .git/config, and upserts. Accepts --name and --description anywhere in the arg list.

(args []string)

Source from the content-addressed store, hash-verified

141// remote from .git/config, and upserts. Accepts --name and --description
142// anywhere in the arg list.
143func cmdWorkdirAdd(args []string) int {
144 name, rest, err := extractWorkdirStringFlag(args, "--name")
145 if err != nil {
146 fmt.Fprintf(os.Stderr, "error: %v\n", err)
147 return 2
148 }
149 description, rest, err := extractWorkdirStringFlag(rest, "--description")
150 if err != nil {
151 fmt.Fprintf(os.Stderr, "error: %v\n", err)
152 return 2
153 }
154 fs := flagSet("workdir add")
155 fs.String("name", "", "short nickname") // for -h rendering only
156 fs.String("description", "", "one-line free-form notes") // for -h rendering only
157 if err := fs.Parse(rest); err != nil {
158 return 2
159 }
160 if fs.NArg() != 1 {
161 fmt.Fprintln(os.Stderr, "error: workdir add requires exactly one path")
162 return 2
163 }
164 path := fs.Arg(0)
165 abs, err := filepath.Abs(path)
166 if err != nil {
167 fmt.Fprintf(os.Stderr, "error: %v\n", err)
168 return 1
169 }
170 info, err := os.Stat(abs)
171 if err != nil {
172 fmt.Fprintf(os.Stderr, "error: %v\n", err)
173 return 1
174 }
175 if !info.IsDir() {
176 fmt.Fprintf(os.Stderr, "error: %s is not a directory\n", abs)
177 return 1
178 }
179
180 remote := detectGitRemote(abs)
181
182 db, rc := openFlowDBForWorkdir()
183 if rc != 0 {
184 return rc
185 }
186 defer db.Close()
187
188 if err := flowdb.UpsertWorkdir(db, abs, name, description, remote); err != nil {
189 fmt.Fprintf(os.Stderr, "error: %v\n", err)
190 return 1
191 }
192 tag := ""
193 if name != "" {
194 tag = fmt.Sprintf(" [name=%s]", name)
195 }
196 fmt.Printf("Registered workdir %s%s\n", abs, tag)
197 if description != "" {
198 fmt.Printf(" %s\n", description)
199 }
200 return 0

Callers 1

cmdWorkdirFunction · 0.85

Calls 6

UpsertWorkdirFunction · 0.92
extractWorkdirStringFlagFunction · 0.85
flagSetFunction · 0.85
detectGitRemoteFunction · 0.85
openFlowDBForWorkdirFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected