Skip to content

Commit

Permalink
chore(pgs): prevent deleting prose project
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jan 19, 2025
1 parent 310e14b commit 8e4e5f5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pgs/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/picosh/utils"
)

func projectTable(styles common.Styles, projects []*db.Project, width int) *table.Table {
func projectTable(projects []*db.Project, width int) *table.Table {
headers := []string{
"Name",
"Last Updated",
Expand Down Expand Up @@ -257,7 +257,7 @@ func (c *Cmd) ls() error {
c.output("no projects found")
}

t := projectTable(c.Styles, projects, c.Width)
t := projectTable(projects, c.Width)
c.output(t.String())

return nil
Expand Down Expand Up @@ -374,7 +374,7 @@ func (c *Cmd) depends(projectName string) error {
return nil
}

t := projectTable(c.Styles, projects, c.Width)
t := projectTable(projects, c.Width)
c.output(t.String())

return nil
Expand All @@ -386,6 +386,10 @@ func (c *Cmd) prune(prefix string, keepNumLatest int) error {
c.Log.Info("user running `clean` command", "user", c.User.Name, "prefix", prefix)
c.output(fmt.Sprintf("searching for projects that match prefix (%s) and are not linked to other projects", prefix))

if prefix == "prose" {
return fmt.Errorf("cannot delete `prose` because it is used by prose.sh and is protected")
}

if prefix == "" || prefix == "*" {
e := fmt.Errorf("must provide valid prefix")
return e
Expand Down Expand Up @@ -462,6 +466,10 @@ func (c *Cmd) prune(prefix string, keepNumLatest int) error {

func (c *Cmd) rm(projectName string) error {
c.Log.Info("user running `rm` command", "user", c.User.Name, "project", projectName)
if projectName == "prose" {
return fmt.Errorf("cannot delete `prose` because it is used by prose.sh and is protected")
}

project, err := c.Dbpool.FindProjectByName(c.User.ID, projectName)
if err == nil {
c.Log.Info("found project, checking dependencies", "project", projectName, "projectID", project.ID)
Expand Down

0 comments on commit 8e4e5f5

Please sign in to comment.