repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
940ace5
parent
1255faf
author
Eric Bower
date
2023-08-19 15:28:47 +0000 UTC
chore(pgs): print summary for prune op
1 files changed,  +18, -2
M pgs/cli.go
+18, -2
 1@@ -272,14 +272,24 @@ func (c *Cmd) prune(prefix string, keepNumLatest int) error {
 2 		if len(links) == 0 {
 3 			rmProjects = append(rmProjects, project)
 4 		} else {
 5-			out := fmt.Sprintf("project (%s) has (%d) projects linked to it, cannot prune", project.Name, len(projects))
 6+			out := fmt.Sprintf("project (%s) has (%d) projects linked to it, cannot prune", project.Name, len(links))
 7 			c.output(out)
 8 		}
 9 	}
10 
11 	goodbye := rmProjects
12 	if keepNumLatest > 0 {
13-		goodbye = rmProjects[:len(rmProjects)-keepNumLatest]
14+		max := len(rmProjects) - (keepNumLatest)
15+		if max <= 0 {
16+			out := fmt.Sprintf(
17+				"no projects available to prune (retention policy: %d, total: %d)",
18+				keepNumLatest,
19+				len(rmProjects),
20+			)
21+			c.output(out)
22+			return nil
23+		}
24+		goodbye = rmProjects[:max]
25 	}
26 
27 	for _, project := range goodbye {
28@@ -302,6 +312,12 @@ func (c *Cmd) prune(prefix string, keepNumLatest int) error {
29 		}
30 	}
31 
32+	c.output("\nsummary")
33+	c.output("=======")
34+	for _, project := range goodbye {
35+		c.output(fmt.Sprintf("project (%s) removed", project.Name))
36+	}
37+
38 	return nil
39 }
40