diff --git a/go.mod b/go.mod index bffe4c9..1347520 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,6 @@ require ( github.com/pterm/pterm v0.12.35 github.com/spf13/afero v1.8.0 github.com/urfave/cli/v2 v2.3.0 + github.com/visionmedia/go-cli-log v0.0.0-20151214173634-914d1b040b20 // indirect google.golang.org/protobuf v1.27.1 ) diff --git a/go.sum b/go.sum index 1435c73..0772536 100644 --- a/go.sum +++ b/go.sum @@ -171,6 +171,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/visionmedia/go-cli-log v0.0.0-20151214173634-914d1b040b20 h1:RDJ3ggSqBL4Mu/ANRKmxuLrwnupJsvHRDXe4/KI+HWE= +github.com/visionmedia/go-cli-log v0.0.0-20151214173634-914d1b040b20/go.mod h1:iljxuLc3m07jsXOWojqehoTp/Fh0XP7irbhV+6sYNGc= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/internal/cli/mfer.go b/internal/cli/mfer.go index 5d03e65..9694b1a 100644 --- a/internal/cli/mfer.go +++ b/internal/cli/mfer.go @@ -1,11 +1,13 @@ package cli import ( + "errors" "fmt" - "log" "os" "time" + log "github.com/visionmedia/go-cli-log" + "git.eeqj.de/sneak/mfer/mfer" "github.com/davecgh/go-spew/spew" "github.com/pterm/pterm" @@ -89,12 +91,12 @@ func (mfa *CLIApp) run() { if err != nil { mfa.exitCode = 1 - log.Fatal(err) + log.Error(err) } } func (mfa *CLIApp) validateManifestOperation(c *cli.Context) error { - log.Fatal("unimplemented") + log.Error(errors.New("unimplemented")) return nil } diff --git a/mfer/manifest.go b/mfer/manifest.go index bc06af7..552f0b4 100644 --- a/mfer/manifest.go +++ b/mfer/manifest.go @@ -4,8 +4,10 @@ import ( "fmt" "io" "io/fs" + "path/filepath" "strings" + "github.com/davecgh/go-spew/spew" "github.com/spf13/afero" ) @@ -14,8 +16,13 @@ type ManifestFile struct { FileInfo fs.FileInfo } +func (m *ManifestFile) String() string { + return fmt.Sprintf("", m.Path) +} + type Manifest struct { SourceFS afero.Fs + SourceFSRoot string Files []*ManifestFile ScanOptions *ManifestScanOptions TotalFileSize int64 @@ -27,11 +34,22 @@ type ManifestScanOptions struct { } func NewFromPath(inputPath string, options *ManifestScanOptions) (*Manifest, error) { - afs := afero.NewBasePathFs(afero.NewOsFs(), inputPath) - return NewFromFilesystem(afs, options) + abs, err := filepath.Abs(inputPath) + if err != nil { + return nil, err + } + afs := afero.NewBasePathFs(afero.NewOsFs(), abs) + spew.Dump(afs) + m, err := NewFromFS(afs, options) + if err != nil { + return nil, err + } + m.SourceFSRoot = abs + spew.Dump(m) + return m, nil } -func NewFromFilesystem(fs afero.Fs, options *ManifestScanOptions) (*Manifest, error) { +func NewFromFS(fs afero.Fs, options *ManifestScanOptions) (*Manifest, error) { m := &Manifest{ SourceFS: fs, ScanOptions: options, @@ -41,7 +59,7 @@ func NewFromFilesystem(fs afero.Fs, options *ManifestScanOptions) (*Manifest, er } func (m *Manifest) Scan() { - afero.Walk(m.SourceFS, "", func(path string, info fs.FileInfo, err error) error { + afero.Walk(m.SourceFS, "./", func(path string, info fs.FileInfo, err error) error { if m.ScanOptions.IgnoreDotfiles && strings.HasPrefix(path, ".") { // FIXME make this check all path components BUG @@ -54,6 +72,9 @@ func (m *Manifest) Scan() { } fmt.Printf("path = %s\n", path) + spew.Dump(path) + spew.Dump(info) + fileinfo, staterr := m.SourceFS.Stat(path) if staterr != nil { panic(staterr)