mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-21 19:47:06 +00:00
Implement CLI scaffold
This commit is contained in:
54
cmd/mailfull/main.go
Normal file
54
cmd/mailfull/main.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/directorz/mailfull-go"
|
||||
"github.com/directorz/mailfull-go/cmd/mailfull/command"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
version = mailfull.Version
|
||||
gittag = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
if gittag != "" {
|
||||
version = version + "-" + gittag
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := &cli.CLI{
|
||||
Name: filepath.Base(os.Args[0]),
|
||||
Version: version,
|
||||
Args: os.Args[1:],
|
||||
}
|
||||
|
||||
meta := command.Meta{
|
||||
UI: &cli.BasicUi{
|
||||
Reader: os.Stdin,
|
||||
Writer: os.Stdout,
|
||||
ErrorWriter: os.Stderr,
|
||||
},
|
||||
CmdName: c.Name,
|
||||
Version: c.Version,
|
||||
}
|
||||
|
||||
c.Commands = map[string]cli.CommandFactory{
|
||||
"init": func() (cli.Command, error) {
|
||||
meta.SubCmdName = c.Subcommand()
|
||||
return &command.InitCommand{Meta: meta}, nil
|
||||
},
|
||||
}
|
||||
|
||||
exitCode, err := c.Run()
|
||||
if err != nil {
|
||||
fmt.Fprintf(meta.UI.ErrorWriter, "%v\n", err)
|
||||
}
|
||||
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
Reference in New Issue
Block a user