mfer/internal/cli/gen.go

55 lines
957 B
Go
Raw Normal View History

package cli
import (
2022-12-06 02:29:01 +00:00
"bytes"
"path/filepath"
2022-12-06 02:29:01 +00:00
"git.eeqj.de/sneak/mfer/internal/log"
"git.eeqj.de/sneak/mfer/mfer"
"github.com/urfave/cli/v2"
)
2022-12-05 22:59:08 +00:00
func (mfa *CLIApp) generateManifestOperation(ctx *cli.Context) error {
2022-12-06 02:29:01 +00:00
log.Debug("generateManifestOperation()")
2022-12-05 22:59:08 +00:00
myArgs := ctx.Args()
2022-12-06 02:29:01 +00:00
log.Dump(myArgs)
opts := &mfer.ManifestScanOptions{
2022-12-05 22:59:08 +00:00
IgnoreDotfiles: ctx.Bool("IgnoreDotfiles"),
FollowSymLinks: ctx.Bool("FollowSymLinks"),
}
2022-12-06 02:29:01 +00:00
paths := make([]string, ctx.Args().Len()-1)
2022-12-05 22:59:08 +00:00
for i := 0; i < ctx.Args().Len(); i++ {
2022-12-06 02:29:01 +00:00
ap, err := filepath.Abs(ctx.Args().Get(i))
if err != nil {
return err
}
log.Dump(ap)
paths = append(paths, ap)
2022-12-05 22:59:08 +00:00
}
mf, err := mfer.NewFromPaths(opts, paths...)
if err != nil {
panic(err)
}
2022-12-06 02:29:01 +00:00
mf.WithContext(ctx.Context)
log.Dump(mf)
err = mf.Scan()
if err != nil {
return err
}
buf := new(bytes.Buffer)
err = mf.WriteTo(buf)
if err != nil {
return err
}
2022-12-06 02:29:01 +00:00
dat := buf.Bytes()
2022-12-06 02:29:01 +00:00
log.Dump(dat)
return nil
}