builds now
This commit is contained in:
24
internal/cli/cli.go
Normal file
24
internal/cli/cli.go
Normal file
@@ -0,0 +1,24 @@
|
||||
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 string) int {
|
||||
m := &CLIApp{}
|
||||
m.appname = Appname
|
||||
m.version = Version
|
||||
m.exitCode = 0
|
||||
|
||||
m.run()
|
||||
return m.exitCode
|
||||
}
|
||||
51
internal/cli/manifest.go
Normal file
51
internal/cli/manifest.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"git.eeqj.de/sneak/mfer/mfer"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
innerpb *mfer.MFFileInner
|
||||
outerpb *mfer.MFFile
|
||||
fileCount int64
|
||||
totalSize int64
|
||||
afs afero.Fs
|
||||
}
|
||||
|
||||
func (m *Job) scanForFiles() error {
|
||||
|
||||
m.innerpb = &mfer.MFFileInner{}
|
||||
m.innerpb.Version = mfer.MFFileInner_ONE
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
walkErr := filepath.Walk(m.sourcePath, func(itemPath string, info os.FileInfo, err error) error {
|
||||
|
||||
// we do not include the manifest file in the manifest
|
||||
if itemPath == "index.mf" {
|
||||
return nil
|
||||
}
|
||||
|
||||
fpi := mfer.MFFilePath{}
|
||||
fpi.Path = itemPath
|
||||
fpi.Size = info.Size()
|
||||
m.innerpb.Files = append(m.innerpb.Files, &fpi)
|
||||
m.fileCount++
|
||||
m.totalSize += fpi.Size
|
||||
return nil
|
||||
})
|
||||
|
||||
if walkErr != nil {
|
||||
log.Fatal(walkErr)
|
||||
return walkErr
|
||||
}
|
||||
|
||||
fmt.Printf("%#v\n", m.innerpb)
|
||||
fmt.Printf("filecount = %#v\n", m.fileCount)
|
||||
fmt.Printf("totalsize = %#v\n", m.totalSize)
|
||||
return nil
|
||||
}
|
||||
|
||||
*/
|
||||
115
internal/cli/mfer.go
Normal file
115
internal/cli/mfer.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"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 (m *CLIApp) printBanner() {
|
||||
s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(m.appname)).Srender()
|
||||
pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter
|
||||
}
|
||||
|
||||
func (m *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 (m *CLIApp) run() {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CLIApp) validateManifestOperation(c *cli.Context) error {
|
||||
log.Fatal("unimplemented")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *CLIApp) generateManifestOperation(c *cli.Context) error {
|
||||
fmt.Println("generateManifest()")
|
||||
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")
|
||||
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user