mfer/src/app.go

90 lines
1.9 KiB
Go
Raw Normal View History

2022-02-02 05:36:20 +00:00
package mfer
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/pterm/pterm"
"github.com/urfave/cli/v2"
)
2022-02-02 05:43:48 +00:00
func printBanner(Appname, Version, Buildarch string) {
2022-02-02 05:36:20 +00:00
s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(Appname)).Srender()
pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter
2022-02-02 05:43:48 +00:00
}
2022-02-02 05:36:20 +00:00
2022-02-02 06:39:50 +00:00
func 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 init() {
if _, exists := os.LookupEnv("NO_COLOR"); exists {
disableStyling()
}
}
2022-02-02 05:43:48 +00:00
func Run(Appname, Version, Buildarch string) int {
printBanner(Appname, Version, Buildarch)
2022-02-02 05:36:20 +00:00
app := &cli.App{
2022-02-02 06:39:50 +00:00
Name: Appname,
Usage: "Manifest generator",
Version: Version,
EnableBashCompletion: true,
2022-02-02 05:36:20 +00:00
Commands: []*cli.Command{
{
Name: "generate",
Aliases: []string{"gen"},
Usage: "Generate manifest file",
Action: func(c *cli.Context) error {
2022-02-02 06:39:50 +00:00
return generateManifest(c.String("input"), c.String("output"))
2022-02-02 05:36:20 +00:00
},
Flags: []cli.Flag{
&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",
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
return 1
}
return 0
}
func generateManifest(path, outputFilename string) error {
fmt.Println("generateManifest()")
walkErr := filepath.Walk(path, func(itemPath string, info os.FileInfo, err error) error {
fmt.Println(itemPath)
return nil
})
if walkErr != nil {
log.Fatal(walkErr)
return walkErr
}
return nil
}