Skip to content

Commit

Permalink
feat(pgs): list urls of all assets in a project with fzf cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jan 19, 2025
1 parent c81384f commit 7d6b68e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
37 changes: 36 additions & 1 deletion pgs/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
}

func getHelpText(styles common.Styles, userName string, width int) string {
helpStr := "Commands: [help, stats, ls, rm, link, unlink, prune, retain, depends, acl, cache]\n"
helpStr := "Commands: [help, stats, ls, fzf, rm, link, unlink, prune, retain, depends, acl, cache]\n"
helpStr += styles.Note.Render("NOTICE:") + " *must* append with `--write` for the changes to persist.\n"

projectName := "projA"
Expand All @@ -71,6 +71,10 @@ func getHelpText(styles common.Styles, userName string, width int) string {
"ls",
"lists projects",
},
{
fmt.Sprintf("fzf %s", projectName),
fmt.Sprintf("lists urls of all assets in %s", projectName),
},
{
fmt.Sprintf("rm %s", projectName),
fmt.Sprintf("delete %s", projectName),
Expand Down Expand Up @@ -288,6 +292,37 @@ func (c *Cmd) unlink(projectName string) error {
return nil
}

func (c *Cmd) fzf(projectName string) error {
project, err := c.Dbpool.FindProjectByName(c.User.ID, projectName)
if err != nil {
return err
}

bucket, err := c.Store.GetBucket(shared.GetAssetBucketName(c.User.ID))
if err != nil {
return err
}

objs, err := c.Store.ListObjects(bucket, project.ProjectDir, true)
if err != nil {
return err
}

for _, obj := range objs {
if strings.Contains(obj.Name(), "._pico_keep_dir") {
continue
}
url := c.Cfg.AssetURL(
c.User.Name,
project.Name,
strings.TrimPrefix(obj.Name(), "/"),
)
c.output(url)
}

return nil
}

func (c *Cmd) link(projectName, linkTo string) error {
c.Log.Info("user running `link` command", "user", c.User.Name, "project", projectName, "link", linkTo)

Expand Down
6 changes: 5 additions & 1 deletion pgs/wish.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ func WishMiddleware(handler *UploadAssetHandler) wish.Middleware {
"cmdArgs", cmdArgs,
)

if cmd == "stats" {
if cmd == "fzf" {
err := opts.fzf(projectName)
opts.bail(err)
return
} else if cmd == "stats" {
err := opts.statsByProject(projectName)
opts.bail(err)
return
Expand Down

0 comments on commit 7d6b68e

Please sign in to comment.