next (#5)
All checks were successful
continuous-integration/drone/push Build is passing

Co-authored-by: sneak <sneak@sneak.berlin>
Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2022-12-09 00:02:33 +00:00
parent 7a8a1b4a4a
commit 7df558d8d0
29 changed files with 923 additions and 220 deletions

View File

@@ -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")
}
}