diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39a7681 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/cli/mailfull/mailfull diff --git a/cmd/mailfull/command/init.go b/cmd/mailfull/command/init.go new file mode 100644 index 0000000..11a818e --- /dev/null +++ b/cmd/mailfull/command/init.go @@ -0,0 +1,41 @@ +package command + +import ( + "fmt" + + "github.com/directorz/mailfull-go" +) + +// InitCommand represents a InitCommand. +type InitCommand struct { + Meta +} + +// Synopsis returns a one-line synopsis. +func (c *InitCommand) Synopsis() string { + return "Initializes current directory as a Mailfull repository." +} + +// Help returns long-form help text. +func (c *InitCommand) Help() string { + txt := fmt.Sprintf(` +Usage: + %s %s + +Description: + Initializes current directory as a Mailfull repository. +`, + c.CmdName, c.SubCmdName) + + return txt[1:] +} + +// Run runs the command and returns the exit status. +func (c *InitCommand) Run(args []string) int { + if err := mailfull.InitRepository("."); err != nil { + fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err) + return 1 + } + + return 0 +} diff --git a/cmd/mailfull/command/main.go b/cmd/mailfull/command/main.go new file mode 100644 index 0000000..041cf7a --- /dev/null +++ b/cmd/mailfull/command/main.go @@ -0,0 +1,13 @@ +package command + +import ( + "github.com/mitchellh/cli" +) + +// Meta is for `*Command` struct. +type Meta struct { + UI *cli.BasicUi + CmdName string + SubCmdName string + Version string +} diff --git a/cmd/mailfull/main.go b/cmd/mailfull/main.go new file mode 100644 index 0000000..7c7001f --- /dev/null +++ b/cmd/mailfull/main.go @@ -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) +}