forked from mirror/pkger
if i had a mountain
This commit is contained in:
parent
9a2162e1a0
commit
48c2362aa8
|
@ -90,7 +90,7 @@ func New() (*packCmd, error) {
|
|||
c := &packCmd{}
|
||||
|
||||
c.subs = []command{
|
||||
&serveCmd{}, &statCmd{}, &infoCmd{},
|
||||
&serveCmd{}, &statCmd{}, &infoCmd{}, &pathCmd{},
|
||||
}
|
||||
sort.Slice(c.subs, func(a, b int) bool {
|
||||
return c.subs[a].Name() <= c.subs[b].Name()
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package cmds
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/markbates/pkger"
|
||||
"github.com/markbates/pkger/here"
|
||||
)
|
||||
|
||||
type pathCmd struct {
|
||||
*flag.FlagSet
|
||||
json bool
|
||||
help bool
|
||||
}
|
||||
|
||||
func (s *pathCmd) Name() string {
|
||||
return s.Flags().Name()
|
||||
}
|
||||
|
||||
func (c *pathCmd) Flags() *flag.FlagSet {
|
||||
if c.FlagSet == nil {
|
||||
c.FlagSet = flag.NewFlagSet("path", flag.ExitOnError)
|
||||
// c.BoolVar(&c.json, "json", false, "outputs as json")
|
||||
c.BoolVar(&c.help, "h", false, "prints help information")
|
||||
}
|
||||
return c.FlagSet
|
||||
}
|
||||
|
||||
func (c *pathCmd) Exec(args []string) error {
|
||||
|
||||
c.Parse(args)
|
||||
|
||||
if c.help {
|
||||
c.Usage()
|
||||
return nil
|
||||
}
|
||||
|
||||
args = c.Args()
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("you specify at least one path")
|
||||
}
|
||||
|
||||
paths := map[string]here.Path{}
|
||||
for _, a := range args {
|
||||
pt, err := pkger.Parse(a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
paths[a] = pt
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(paths)
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue