This repository has been archived on 2021-05-09. You can view files and clone it, but cannot push or open issues or pull requests.
gpm/cmd/list.go
John Olheiser ef0d29afa3 Rewrite (#7)
Closes #6

This is, more or less, a fundamental rewrite of gpm.

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: #7
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-committed-by: John Olheiser <john.olheiser@gmail.com>
2021-02-28 13:04:05 +08:00

30 lines
496 B
Go

package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/urfave/cli/v2"
)
var List = cli.Command{
Name: "list",
Aliases: []string{"ls", "l"},
Usage: "List local packages",
Action: doList,
}
func doList(_ *cli.Context) error {
pkgs, err := listPackages()
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
for _, pkg := range pkgs {
s := fmt.Sprintf("%s\t%s\n", pkg.Name, pkg.Import)
_, _ = w.Write([]byte(s))
}
return w.Flush()
}