2020-02-19 16:48:55 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-02-28 05:04:05 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2020-10-07 04:11:36 +00:00
|
|
|
|
2020-02-19 16:48:55 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var List = cli.Command{
|
|
|
|
Name: "list",
|
2021-02-28 05:04:05 +00:00
|
|
|
Aliases: []string{"ls", "l"},
|
2020-02-19 16:48:55 +00:00
|
|
|
Usage: "List local packages",
|
|
|
|
Action: doList,
|
|
|
|
}
|
|
|
|
|
2020-10-07 04:11:36 +00:00
|
|
|
func doList(_ *cli.Context) error {
|
2021-02-28 05:04:05 +00:00
|
|
|
pkgs, err := listPackages()
|
2020-10-07 04:11:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-28 05:04:05 +00:00
|
|
|
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))
|
2020-02-19 16:48:55 +00:00
|
|
|
}
|
2021-02-28 05:04:05 +00:00
|
|
|
return w.Flush()
|
2020-02-19 16:48:55 +00:00
|
|
|
}
|