2022-12-02 00:31:49 +00:00
|
|
|
package cli
|
2022-02-02 09:46:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/pterm/pterm"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
type CLIApp struct {
|
2022-02-02 09:46:25 +00:00
|
|
|
appname string
|
|
|
|
version string
|
|
|
|
buildarch string
|
|
|
|
startupTime time.Time
|
|
|
|
exitCode int
|
|
|
|
errorString string
|
|
|
|
app *cli.App
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
func (m *CLIApp) printBanner() {
|
2022-02-02 09:46:25 +00:00
|
|
|
s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(m.appname)).Srender()
|
|
|
|
pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
func (m *CLIApp) disableStyling() {
|
2022-02-02 09:46:25 +00:00
|
|
|
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 = ""
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
func (m *CLIApp) run() {
|
2022-02-02 09:46:25 +00:00
|
|
|
|
|
|
|
if NO_COLOR {
|
|
|
|
// shoutout to rob pike who thinks it's juvenile
|
|
|
|
m.disableStyling()
|
|
|
|
}
|
|
|
|
|
|
|
|
m.printBanner()
|
|
|
|
|
|
|
|
m.app = &cli.App{
|
|
|
|
Name: m.appname,
|
|
|
|
Usage: "Manifest generator",
|
|
|
|
Version: m.version,
|
|
|
|
EnableBashCompletion: true,
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "generate",
|
|
|
|
Aliases: []string{"gen"},
|
|
|
|
Usage: "Generate manifest file",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return m.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 m.validateManifestOperation(c)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := m.app.Run(os.Args)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
m.exitCode = 1
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
func (m *CLIApp) validateManifestOperation(c *cli.Context) error {
|
2022-02-02 09:46:25 +00:00
|
|
|
log.Fatal("unimplemented")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
func (m *CLIApp) generateManifestOperation(c *cli.Context) error {
|
2022-02-02 09:46:25 +00:00
|
|
|
fmt.Println("generateManifest()")
|
2022-12-02 00:31:49 +00:00
|
|
|
fmt.Printf("called with arg: %s", c.String("input"))
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
mgj, err := NewMFGenerationJobFromFilesystem(c.String("input"))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
mgj.scanForFiles()
|
|
|
|
//mgj.outputFile = c.String("output")
|
2022-02-02 09:46:25 +00:00
|
|
|
|
2022-12-02 00:31:49 +00:00
|
|
|
*/
|
2022-02-02 09:46:25 +00:00
|
|
|
return nil
|
|
|
|
}
|