Add list command to show manifest contents
- mfer list: shows file paths one per line - mfer list -l/--long: shows size, mtime, and path - mfer list --print0: NUL-separated output for xargs -0
This commit is contained in:
parent
a07209fef5
commit
444a4c8f45
65
internal/cli/list.go
Normal file
65
internal/cli/list.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"sneak.berlin/go/mfer/internal/log"
|
||||||
|
"sneak.berlin/go/mfer/mfer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (mfa *CLIApp) listManifestOperation(ctx *cli.Context) error {
|
||||||
|
// Default to ErrorLevel for clean output
|
||||||
|
log.SetLevel(log.ErrorLevel)
|
||||||
|
|
||||||
|
longFormat := ctx.Bool("long")
|
||||||
|
print0 := ctx.Bool("print0")
|
||||||
|
|
||||||
|
// Find manifest file
|
||||||
|
var manifestPath string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if ctx.Args().Len() > 0 {
|
||||||
|
arg := ctx.Args().Get(0)
|
||||||
|
info, statErr := mfa.Fs.Stat(arg)
|
||||||
|
if statErr == nil && info.IsDir() {
|
||||||
|
manifestPath, err = findManifest(mfa.Fs, arg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
manifestPath = arg
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
manifestPath, err = findManifest(mfa.Fs, ".")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load manifest
|
||||||
|
manifest, err := mfer.NewManifestFromFile(mfa.Fs, manifestPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to load manifest: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
files := manifest.Files()
|
||||||
|
|
||||||
|
// Determine line ending
|
||||||
|
lineEnd := "\n"
|
||||||
|
if print0 {
|
||||||
|
lineEnd = "\x00"
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
if longFormat {
|
||||||
|
mtime := time.Unix(f.Mtime.Seconds, int64(f.Mtime.Nanos))
|
||||||
|
_, _ = fmt.Fprintf(mfa.Stdout, "%d\t%s\t%s%s", f.Size, mtime.Format(time.RFC3339), f.Path, lineEnd)
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprintf(mfa.Stdout, "%s%s", f.Path, lineEnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -216,6 +216,26 @@ func (mfa *CLIApp) run(args []string) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "list",
|
||||||
|
Aliases: []string{"ls"},
|
||||||
|
Usage: "List files in manifest",
|
||||||
|
ArgsUsage: "[manifest file]",
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
return mfa.listManifestOperation(c)
|
||||||
|
},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "long",
|
||||||
|
Aliases: []string{"l"},
|
||||||
|
Usage: "Show size and mtime",
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "print0",
|
||||||
|
Usage: "Separate entries with NUL character (for xargs -0)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "fetch",
|
Name: "fetch",
|
||||||
Usage: "fetch manifest and referenced files",
|
Usage: "fetch manifest and referenced files",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user