latest
This commit is contained in:
14
internal/cli/check.go
Normal file
14
internal/cli/check.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
log "github.com/visionmedia/go-cli-log"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func (mfa *CLIApp) checkManifestOperation(c *cli.Context) error {
|
||||
log.Error(errors.New("unimplemented"))
|
||||
return nil
|
||||
}
|
||||
@@ -13,10 +13,11 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func Run(Appname, Version string) int {
|
||||
func Run(Appname, Version, Gitrev string) int {
|
||||
m := &CLIApp{}
|
||||
m.appname = Appname
|
||||
m.version = Version
|
||||
m.gitrev = Gitrev
|
||||
m.exitCode = 0
|
||||
|
||||
m.run()
|
||||
28
internal/cli/gen.go
Normal file
28
internal/cli/gen.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.eeqj.de/sneak/mfer/mfer"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func (mfa *CLIApp) generateManifestOperation(c *cli.Context) error {
|
||||
fmt.Println("generateManifestOperation()")
|
||||
fmt.Printf("called with arg: %s\n", c.String("input"))
|
||||
|
||||
opts := &mfer.ManifestScanOptions{
|
||||
IgnoreDotfiles: c.Bool("IgnoreDotfiles"),
|
||||
FollowSymLinks: c.Bool("FollowSymLinks"),
|
||||
}
|
||||
// FIXME add command flags for ignoring dotfiles and following symlinks
|
||||
mf, err := mfer.NewFromPath(c.String("input"), opts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
spew.Dump(mf)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"git.eeqj.de/sneak/mfer/mfer"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
innerpb *mfer.MFFileInner
|
||||
outerpb *mfer.MFFile
|
||||
fileCount int64
|
||||
totalSize int64
|
||||
afs afero.Fs
|
||||
}
|
||||
|
||||
func (m *Job) scanForFiles() error {
|
||||
|
||||
m.innerpb = &mfer.MFFileInner{}
|
||||
m.innerpb.Version = mfer.MFFileInner_ONE
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
walkErr := filepath.Walk(m.sourcePath, func(itemPath string, info os.FileInfo, err error) error {
|
||||
|
||||
// we do not include the manifest file in the manifest
|
||||
if itemPath == "index.mf" {
|
||||
return nil
|
||||
}
|
||||
|
||||
fpi := mfer.MFFilePath{}
|
||||
fpi.Path = itemPath
|
||||
fpi.Size = info.Size()
|
||||
m.innerpb.Files = append(m.innerpb.Files, &fpi)
|
||||
m.fileCount++
|
||||
m.totalSize += fpi.Size
|
||||
return nil
|
||||
})
|
||||
|
||||
if walkErr != nil {
|
||||
log.Fatal(walkErr)
|
||||
return walkErr
|
||||
}
|
||||
|
||||
fmt.Printf("%#v\n", m.innerpb)
|
||||
fmt.Printf("filecount = %#v\n", m.fileCount)
|
||||
fmt.Printf("totalsize = %#v\n", m.totalSize)
|
||||
return nil
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -1,15 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"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"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@@ -17,10 +14,9 @@ import (
|
||||
type CLIApp struct {
|
||||
appname string
|
||||
version string
|
||||
buildarch string
|
||||
gitrev string
|
||||
startupTime time.Time
|
||||
exitCode int
|
||||
errorString string
|
||||
app *cli.App
|
||||
}
|
||||
|
||||
@@ -40,29 +36,57 @@ func (mfa *CLIApp) disableStyling() {
|
||||
pterm.Fatal.Prefix.Text = ""
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) VersionString() string {
|
||||
return fmt.Sprintf("%s (%s)", mfa.version, mfa.gitrev)
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) run() {
|
||||
mfa.startupTime = time.Now()
|
||||
|
||||
if NO_COLOR {
|
||||
// shoutout to rob pike who thinks it's juvenile
|
||||
mfa.disableStyling()
|
||||
}
|
||||
|
||||
mfa.printBanner()
|
||||
|
||||
mfa.app = &cli.App{
|
||||
Name: mfa.appname,
|
||||
Usage: "Manifest generator",
|
||||
Version: mfa.version,
|
||||
Version: mfa.VersionString(),
|
||||
EnableBashCompletion: true,
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "verbose",
|
||||
Usage: "Verbosity level",
|
||||
Aliases: []string{"v"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
Usage: "don't produce output except on error",
|
||||
Aliases: []string{"q"},
|
||||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "generate",
|
||||
Aliases: []string{"gen"},
|
||||
Usage: "Generate manifest file",
|
||||
Action: func(c *cli.Context) error {
|
||||
if !c.Bool("quiet") {
|
||||
mfa.printBanner()
|
||||
}
|
||||
return mfa.generateManifestOperation(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "FollowSymLinks",
|
||||
Aliases: []string{"follow-symlinks"},
|
||||
Usage: "Resolve encountered symlinks",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "IgnoreDotfiles",
|
||||
Aliases: []string{"ignore-dotfiles"},
|
||||
Usage: "Ignore any dot (hidden) files encountered",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "input",
|
||||
Value: ".",
|
||||
@@ -81,51 +105,27 @@ func (mfa *CLIApp) run() {
|
||||
Name: "check",
|
||||
Usage: "Validate files using manifest file",
|
||||
Action: func(c *cli.Context) error {
|
||||
return mfa.validateManifestOperation(c)
|
||||
if !c.Bool("quiet") {
|
||||
mfa.printBanner()
|
||||
}
|
||||
return mfa.checkManifestOperation(c)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "version",
|
||||
Usage: "Show version",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Printf("%s\n", mfa.VersionString())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
mfa.app.HideVersion = true
|
||||
err := mfa.app.Run(os.Args)
|
||||
|
||||
if err != nil {
|
||||
mfa.exitCode = 1
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) validateManifestOperation(c *cli.Context) error {
|
||||
log.Error(errors.New("unimplemented"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) generateManifestOperation(c *cli.Context) error {
|
||||
fmt.Println("generateManifestOperation()")
|
||||
fmt.Printf("called with arg: %s\n", c.String("input"))
|
||||
|
||||
opts := &mfer.ManifestScanOptions{
|
||||
IgnoreDotfiles: true,
|
||||
FollowSymLinks: false,
|
||||
}
|
||||
mf, err := mfer.NewFromPath(c.String("input"), opts)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
spew.Dump(mf)
|
||||
|
||||
/*
|
||||
|
||||
mgj, err := NewMFGenerationJobFromFilesystem(c.String("input"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
mgj.scanForFiles()
|
||||
//mgj.outputFile = c.String("output")
|
||||
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user