2020-02-19 16:48:55 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-02-28 04:54:01 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
|
|
|
|
2020-02-19 16:48:55 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var List = cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"l"},
|
|
|
|
Usage: "List local packages",
|
|
|
|
Action: doList,
|
|
|
|
}
|
|
|
|
|
2020-10-07 04:11:36 +00:00
|
|
|
func doList(_ *cli.Context) error {
|
2021-02-28 04:20:14 +00:00
|
|
|
pkgs, err := listPackages()
|
2020-10-07 04:11:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-28 04:54:01 +00:00
|
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
2021-02-28 04:20:14 +00:00
|
|
|
for _, pkg := range pkgs {
|
2021-02-28 04:54:01 +00:00
|
|
|
s := fmt.Sprintf("%s\t%s\n", pkg.Name, pkg.Import)
|
|
|
|
_, _ = w.Write([]byte(s))
|
2020-02-19 16:48:55 +00:00
|
|
|
}
|
2021-02-28 04:54:01 +00:00
|
|
|
return w.Flush()
|
2020-02-19 16:48:55 +00:00
|
|
|
}
|