Co-authored-by: sneak <sneak@sneak.berlin> Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
@@ -3,12 +3,11 @@ package cli
|
||||
import (
|
||||
"errors"
|
||||
|
||||
log "github.com/visionmedia/go-cli-log"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func (mfa *CLIApp) checkManifestOperation(c *cli.Context) error {
|
||||
log.Error(errors.New("unimplemented"))
|
||||
log.WithError(errors.New("unimplemented"))
|
||||
return nil
|
||||
}
|
||||
|
||||
12
internal/cli/entry_test.go
Normal file
12
internal/cli/entry_test.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
m := &CLIApp{}
|
||||
assert.NotNil(t, m)
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func (mfa *CLIApp) fetchManifestOperation(c *cli.Context) error {
|
||||
fmt.Println("fetchManifestOperation()")
|
||||
return nil
|
||||
log.Debugf("fetchManifestOperation()")
|
||||
panic("not implemented")
|
||||
return nil //nolint
|
||||
}
|
||||
|
||||
@@ -1,36 +1,54 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"path/filepath"
|
||||
|
||||
"git.eeqj.de/sneak/mfer/internal/log"
|
||||
"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()")
|
||||
myArgs := c.Args()
|
||||
spew.Dump(myArgs)
|
||||
|
||||
fmt.Printf("%#v\n", c.Args().First())
|
||||
if c.Args().Len() > 0 {
|
||||
fmt.Printf("%#v\n", c.Args().Get(1))
|
||||
}
|
||||
|
||||
// fmt.Printf("called with arg: %s\n", c.String("input"))
|
||||
func (mfa *CLIApp) generateManifestOperation(ctx *cli.Context) error {
|
||||
log.Debug("generateManifestOperation()")
|
||||
myArgs := ctx.Args()
|
||||
log.Dump(myArgs)
|
||||
|
||||
opts := &mfer.ManifestScanOptions{
|
||||
IgnoreDotfiles: c.Bool("IgnoreDotfiles"),
|
||||
FollowSymLinks: c.Bool("FollowSymLinks"),
|
||||
IgnoreDotfiles: ctx.Bool("IgnoreDotfiles"),
|
||||
FollowSymLinks: ctx.Bool("FollowSymLinks"),
|
||||
}
|
||||
// FIXME add command flags for ignoring dotfiles and following symlinks
|
||||
mf, err := mfer.NewFromPath(c.String("input"), opts)
|
||||
paths := make([]string, ctx.Args().Len()-1)
|
||||
for i := 0; i < ctx.Args().Len(); i++ {
|
||||
ap, err := filepath.Abs(ctx.Args().Get(i))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Dump(ap)
|
||||
paths = append(paths, ap)
|
||||
}
|
||||
mf, err := mfer.NewFromPaths(opts, paths...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
mf.WithContext(ctx.Context)
|
||||
|
||||
spew.Dump(mf)
|
||||
log.Dump(mf)
|
||||
|
||||
err = mf.Scan()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
err = mf.WriteTo(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dat := buf.Bytes()
|
||||
|
||||
log.Dump(dat)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
log "github.com/visionmedia/go-cli-log"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"git.eeqj.de/sneak/mfer/internal/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -20,34 +18,47 @@ type CLIApp struct {
|
||||
app *cli.App
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) printBanner() {
|
||||
s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(mfa.appname)).Srender()
|
||||
pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter
|
||||
}
|
||||
const banner = ` ___ ___ ___ ___
|
||||
/__/\ / /\ / /\ / /\
|
||||
| |::\ / /:/_ / /:/_ / /::\
|
||||
| |:|:\ / /:/ /\ / /:/ /\ / /:/\:\
|
||||
__|__|:|\:\ / /:/ /:/ / /:/ /:/_ / /:/~/:/
|
||||
/__/::::| \:\ /__/:/ /:/ /__/:/ /:/ /\ /__/:/ /:/___
|
||||
\ \:\~~\__\/ \ \:\/:/ \ \:\/:/ /:/ \ \:\/:::::/
|
||||
\ \:\ \ \::/ \ \::/ /:/ \ \::/~~~~
|
||||
\ \:\ \ \:\ \ \:\/:/ \ \:\
|
||||
\ \:\ \ \:\ \ \::/ \ \:\
|
||||
\__\/ \__\/ \__\/ \__\/`
|
||||
|
||||
func (mfa *CLIApp) disableStyling() {
|
||||
pterm.DisableColor()
|
||||
pterm.DisableStyling()
|
||||
pterm.Debug.Prefix.Text = ""
|
||||
pterm.Info.Prefix.Text = ""
|
||||
pterm.Success.Prefix.Text = ""
|
||||
pterm.Warning.Prefix.Text = ""
|
||||
pterm.Error.Prefix.Text = ""
|
||||
pterm.Fatal.Prefix.Text = ""
|
||||
func (mfa *CLIApp) printBanner() {
|
||||
fmt.Println(banner)
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) VersionString() string {
|
||||
return fmt.Sprintf("%s (%s)", mfa.version, mfa.gitrev)
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) setVerbosity(v int) {
|
||||
_, present := os.LookupEnv("MFER_DEBUG")
|
||||
if present {
|
||||
log.EnableDebugLogging()
|
||||
} else {
|
||||
log.SetLevelFromVerbosity(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (mfa *CLIApp) run() {
|
||||
mfa.startupTime = time.Now()
|
||||
|
||||
if NO_COLOR {
|
||||
// shoutout to rob pike who thinks it's juvenile
|
||||
mfa.disableStyling()
|
||||
log.DisableStyling()
|
||||
}
|
||||
|
||||
log.Init()
|
||||
|
||||
var verbosity int
|
||||
|
||||
mfa.app = &cli.App{
|
||||
Name: mfa.appname,
|
||||
Usage: "Manifest generator",
|
||||
@@ -58,6 +69,7 @@ func (mfa *CLIApp) run() {
|
||||
Name: "verbose",
|
||||
Usage: "Verbosity level",
|
||||
Aliases: []string{"v"},
|
||||
Count: &verbosity,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
@@ -74,6 +86,7 @@ func (mfa *CLIApp) run() {
|
||||
if !c.Bool("quiet") {
|
||||
mfa.printBanner()
|
||||
}
|
||||
mfa.setVerbosity(verbosity)
|
||||
return mfa.generateManifestOperation(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
@@ -87,13 +100,6 @@ func (mfa *CLIApp) run() {
|
||||
Aliases: []string{"ignore-dotfiles"},
|
||||
Usage: "Ignore any dot (hidden) files encountered",
|
||||
},
|
||||
// FIXME this should be a positional arg
|
||||
&cli.StringFlag{
|
||||
Name: "input",
|
||||
Value: ".",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "Specify input directory.",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "output",
|
||||
Value: "./index.mf",
|
||||
@@ -109,6 +115,7 @@ func (mfa *CLIApp) run() {
|
||||
if !c.Bool("quiet") {
|
||||
mfa.printBanner()
|
||||
}
|
||||
mfa.setVerbosity(verbosity)
|
||||
return mfa.checkManifestOperation(c)
|
||||
},
|
||||
},
|
||||
@@ -127,6 +134,7 @@ func (mfa *CLIApp) run() {
|
||||
if !c.Bool("quiet") {
|
||||
mfa.printBanner()
|
||||
}
|
||||
mfa.setVerbosity(verbosity)
|
||||
return mfa.fetchManifestOperation(c)
|
||||
},
|
||||
},
|
||||
@@ -137,6 +145,6 @@ func (mfa *CLIApp) run() {
|
||||
err := mfa.app.Run(os.Args)
|
||||
if err != nil {
|
||||
mfa.exitCode = 1
|
||||
log.Error(err)
|
||||
log.WithError(err).Debugf("exiting")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user