package cli import ( "fmt" "log" "os" "time" "git.eeqj.de/sneak/mfer/mfer" "github.com/davecgh/go-spew/spew" "github.com/pterm/pterm" "github.com/urfave/cli/v2" ) type CLIApp struct { appname string version string buildarch string startupTime time.Time exitCode int errorString string 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) run() { 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, EnableBashCompletion: true, Commands: []*cli.Command{ { Name: "generate", Aliases: []string{"gen"}, Usage: "Generate manifest file", Action: func(c *cli.Context) error { return mfa.generateManifestOperation(c) }, 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", }, }, }, { Name: "check", Usage: "Validate files using manifest file", Action: func(c *cli.Context) error { return mfa.validateManifestOperation(c) }, }, }, } err := mfa.app.Run(os.Args) if err != nil { mfa.exitCode = 1 log.Fatal(err) } } func (mfa *CLIApp) validateManifestOperation(c *cli.Context) error { log.Fatal("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 }