Skip to content

configure project add/list/delete: Add CRUD subcommands for project management #56

@ewega

Description

@ewega

Problem

configure project is currently a single command that creates a project. There are no subcommands for listing existing projects or deleting them. This is inconsistent with the CRUD pattern established by configure connection (which has add, list, update, delete, test) and the restructuring planned for configure scope in #55.

Users who want to inspect what projects exist, or remove a stale project, must use the DevLake API directly (or the Config UI).

Current command tree

configure project            ← RunE = create project (only action)

Desired command tree

configure project            ← no RunE, prints help
  ├── add                    ← current project creation logic
  ├── list                   ← list projects
  └── delete                 ← delete a project by name

Dependencies

Blocked by:

Blocks: nothing directly

Parallel with: #55 (scope CRUD) — independent files, can be done in parallel

Scope of changes

1. Create cmd/configure_project_add.go

Move the current runConfigureProjects() from configure_projects.go into a new add subcommand:

func newProjectAddCmd() *cobra.Command {
    var opts ProjectOpts
    cmd := &cobra.Command{
        Use:   "add",
        Short: "Create a DevLake project and start data collection",
        RunE: func(cmd *cobra.Command, args []string) error {
            return runProjectAdd(cmd, args, &opts)
        },
    }
    // Move all current project flags here
    cmd.Flags().StringVar(&opts.ProjectName, "project-name", "", ...)
    cmd.Flags().StringVar(&opts.Cron, "cron", "0 0 * * *", ...)
    // ...
    return cmd
}

2. Create cmd/configure_project_list.go

// gh devlake configure project list

Implementation:

  • Call new client method client.ListProjects()GET /projects
  • Render results as a table: Name | Description | Blueprint ID | Blueprint Status
  • No flags needed — lists all projects

3. Create cmd/configure_project_delete.go

// gh devlake configure project delete --name my-project
// gh devlake configure project delete   (interactive: pick from list)

Implementation:

  • In flag mode, require --name
  • In interactive mode: list projects → pick one → confirm deletion
  • Call new client method client.DeleteProject(name)DELETE /projects/{name}
  • Confirm before deletion (warn about losing blueprint and sync schedule)

4. Update configure_projects.go

  • Remove RunE from the parent project command
  • Remove flag registrations (they move to add)
  • Register add, list, delete as subcommands

5. Add client methods to internal/devlake/client.go

// ListProjects returns all DevLake projects.
func (c *Client) ListProjects() ([]Project, error) {
    result, err := doGet[struct{ Projects []Project }](c, "/projects")
    if err != nil {
        return nil, err
    }
    return result.Projects, nil
}

// DeleteProject deletes a project by name.
func (c *Client) DeleteProject(name string) error {
    url := fmt.Sprintf("%s/projects/%s", c.BaseURL, name)
    req, _ := http.NewRequest(http.MethodDelete, url, nil)
    resp, err := c.HTTPClient.Do(req)
    // ... error handling ...
}

Note: The exact response shape of GET /projects should be verified against the DevLake API. The upstream code is at backend/server/api/project/project.go in the apache/incubator-devlake repo.

6. Verify orchestrators are unaffected

collectAndFinalizeProject() in helpers.go calls finalizeProject() directly — it does not invoke the Cobra command. The restructuring should not affect orchestrators.

Acceptance criteria

  • gh devlake configure project prints help showing add, list, delete
  • gh devlake configure project add creates a project (same as current behavior)
  • gh devlake configure project add --project-name my-team works in flag mode
  • gh devlake configure project list shows a table of all projects
  • gh devlake configure project delete --name my-project deletes a project
  • Interactive delete lists projects → user picks one → confirms → deletes
  • Orchestrators (configureAllPhases, collectAndFinalizeProject) continue to work
  • go build ./... and go test ./... pass
  • README updated

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestrefactorCode restructure, no behavior change

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions