MCPcopy Index your code
hub / github.com/rilldata/rill / InferProjectName

Method InferProjectName

cli/pkg/cmdutil/helper.go:366–394  ·  view source on GitHub ↗

InferProjectName infers a project name from the given path. If multiple projects are found, it prompts the user to select one (or errors in non-interactive mode). The hint (e.g. "use --project to specify the name") is appended to error messages.

(ctx context.Context, pathToProject, hint string)

Source from the content-addressed store, hash-verified

364// If multiple projects are found, it prompts the user to select one (or errors in non-interactive mode).
365// The hint (e.g. "use --project to specify the name") is appended to error messages.
366func (h *Helper) InferProjectName(ctx context.Context, pathToProject, hint string) (string, error) {
367 errorfWithHint := func(format string, a ...any) error {
368 if hint != "" {
369 return fmt.Errorf(format+" (%s)", append(append([]any{}, a...), hint)...)
370 }
371 return fmt.Errorf(format, a...)
372 }
373
374 projects, err := h.InferProjects(ctx, h.Org, pathToProject)
375 if err != nil {
376 if errors.Is(err, ErrInferProjectFailed) {
377 return "", errorfWithHint("%w", err)
378 }
379 return "", errorfWithHint("failed to infer project: %w", err)
380 }
381 if len(projects) == 1 {
382 return projects[0].Name, nil
383 }
384
385 if !h.Interactive {
386 return "", errorfWithHint("multiple projects match the current directory; you must explicitly specify a project")
387 }
388
389 var names []string
390 for _, p := range projects {
391 names = append(names, p.Name)
392 }
393 return SelectPrompt("Select project", names, "")
394}
395
396func (h *Helper) InferProjects(ctx context.Context, org, path string) ([]*adminv1.Project, error) {
397 path, err := fileutil.ExpandHome(path)

Callers 15

LogsCmdFunction · 0.80
StatusCmdFunction · 0.80
HibernateCmdFunction · 0.80
RefreshCmdFunction · 0.80
DeleteCmdFunction · 0.80
PartitionsCmdFunction · 0.80
ShowCmdFunction · 0.80
DescribeCmdFunction · 0.80
TablesCmdFunction · 0.80
StopCmdFunction · 0.80
StartCmdFunction · 0.80
DeleteCmdFunction · 0.80

Calls 3

InferProjectsMethod · 0.95
SelectPromptFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected