rollup from next branch (#4)
All checks were successful
continuous-integration/drone/push Build is passing

Co-authored-by: sneak <sneak@sneak.berlin>
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
2022-12-04 07:59:36 +00:00
parent eb3b685aa3
commit 7a8a1b4a4a
665 changed files with 832 additions and 248432 deletions

14
internal/cli/check.go Normal file
View 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
}

25
internal/cli/entry.go Normal file
View File

@@ -0,0 +1,25 @@
package cli
import (
"os"
)
var NO_COLOR bool
func init() {
NO_COLOR = false
if _, exists := os.LookupEnv("NO_COLOR"); exists {
NO_COLOR = true
}
}
func Run(Appname, Version, Gitrev string) int {
m := &CLIApp{}
m.appname = Appname
m.version = Version
m.gitrev = Gitrev
m.exitCode = 0
m.run()
return m.exitCode
}

12
internal/cli/fetch.go Normal file
View File

@@ -0,0 +1,12 @@
package cli
import (
"fmt"
"github.com/urfave/cli/v2"
)
func (mfa *CLIApp) fetchManifestOperation(c *cli.Context) error {
fmt.Println("fetchManifestOperation()")
return nil
}

36
internal/cli/gen.go Normal file
View File

@@ -0,0 +1,36 @@
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()")
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"))
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
}

142
internal/cli/mfer.go Normal file
View File

@@ -0,0 +1,142 @@
package cli
import (
"fmt"
"os"
"time"
log "github.com/visionmedia/go-cli-log"
"github.com/pterm/pterm"
"github.com/urfave/cli/v2"
)
type CLIApp struct {
appname string
version string
gitrev string
startupTime time.Time
exitCode int
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
}
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) 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.app = &cli.App{
Name: mfa.appname,
Usage: "Manifest generator",
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",
},
// 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",
Aliases: []string{"o"},
Usage: "Specify output filename",
},
},
},
{
Name: "check",
Usage: "Validate files using manifest file",
Action: func(c *cli.Context) error {
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
},
},
{
Name: "fetch",
Usage: "fetch manifest and referenced files",
Action: func(c *cli.Context) error {
if !c.Bool("quiet") {
mfa.printBanner()
}
return mfa.fetchManifestOperation(c)
},
},
},
}
mfa.app.HideVersion = true
err := mfa.app.Run(os.Args)
if err != nil {
mfa.exitCode = 1
log.Error(err)
}
}