stat / info

This commit is contained in:
Mark Bates 2019-10-17 17:03:04 -04:00
parent 372454529c
commit 372c9371cf
7 changed files with 1130 additions and 33 deletions

View File

@ -9,6 +9,9 @@ import (
"github.com/markbates/pkger/pkging/pkgutil"
)
// Apply will wrap the current implementation
// of pkger.Pkger with the new pkg. This allows
// for layering of pkging.Pkger implementations.
func Apply(pkg pkging.Pkger, err error) error {
gil.Lock()
defer gil.Unlock()

View File

@ -1,11 +1,11 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"github.com/markbates/pkger"
"github.com/markbates/pkger/pkging"
)
type infoCmd struct {
@ -16,41 +16,29 @@ func (s *infoCmd) Name() string {
return s.Flags().Name()
}
func (f *infoCmd) Flags() *flag.FlagSet {
if f.FlagSet == nil {
f.FlagSet = flag.NewFlagSet("info", flag.ExitOnError)
func (r *infoCmd) Flags() *flag.FlagSet {
if r.FlagSet == nil {
r.FlagSet = flag.NewFlagSet("info", flag.ExitOnError)
}
return f.FlagSet
return r.FlagSet
}
func (f *infoCmd) Exec(args []string) error {
func (r *infoCmd) Exec(args []string) error {
if len(args) == 0 {
args = []string{"."}
}
for _, a := range args {
f, err := pkger.Open(a)
if err != nil {
return err
}
defer f.Close()
fi, err := f.Stat()
fi, err := pkger.Info(a)
if err != nil {
return err
}
if fi.IsDir() {
files, err := f.Readdir(-1)
if err != nil {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
if err := enc.Encode(fi); err != nil {
return err
}
for _, ff := range files {
fmt.Println(pkging.NewFileInfo(ff))
}
continue
}
fmt.Println(pkging.NewFileInfo(fi))
}
return nil

View File

@ -90,7 +90,7 @@ func New() (*packCmd, error) {
c := &packCmd{}
c.subs = []command{
&readCmd{}, &serveCmd{}, &infoCmd{},
&readCmd{}, &serveCmd{}, &statCmd{}, &infoCmd{},
}
sort.Slice(c.subs, func(a, b int) bool {
return c.subs[a].Name() <= c.subs[b].Name()

57
cmd/pkger/stat.go Normal file
View File

@ -0,0 +1,57 @@
package main
import (
"flag"
"fmt"
"github.com/markbates/pkger"
"github.com/markbates/pkger/pkging"
)
type statCmd struct {
*flag.FlagSet
}
func (s *statCmd) Name() string {
return s.Flags().Name()
}
func (f *statCmd) Flags() *flag.FlagSet {
if f.FlagSet == nil {
f.FlagSet = flag.NewFlagSet("stat", flag.ExitOnError)
}
return f.FlagSet
}
func (f *statCmd) Exec(args []string) error {
if len(args) == 0 {
args = []string{"."}
}
for _, a := range args {
f, err := pkger.Open(a)
if err != nil {
return err
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return err
}
if fi.IsDir() {
files, err := f.Readdir(-1)
if err != nil {
return err
}
for _, ff := range files {
fmt.Println(pkging.NewFileInfo(ff))
}
continue
}
fmt.Println(pkging.NewFileInfo(fi))
}
return nil
}

View File

@ -18,7 +18,7 @@ type Info struct {
Dir string
ImportPath string
Name string
Imports []string
// Imports []string
Module Module
}
@ -26,7 +26,7 @@ func (fi Info) MarshalJSON() ([]byte, error) {
mm := map[string]interface{}{
"ImportPath": fi.ImportPath,
"Name": fi.Name,
"Imports": fi.Imports,
// "Imports": fi.Imports,
"Module": fi.Module,
}

View File

@ -2,6 +2,9 @@ module github.com/markbates/pkger/examples/app
go 1.13
require github.com/markbates/pkger v0.0.0
require (
github.com/gobuffalo/buffalo v0.14.11 // indirect
github.com/markbates/pkger v0.0.0
)
replace github.com/markbates/pkger => ../../
replace github.com/markbates/pkger => ../../../

File diff suppressed because it is too large Load Diff