diff --git a/cmd/mailfull/command/commit.go b/cmd/mailfull/command/commit.go new file mode 100644 index 0000000..2bd15d7 --- /dev/null +++ b/cmd/mailfull/command/commit.go @@ -0,0 +1,54 @@ +package command + +import ( + "fmt" + + "github.com/directorz/mailfull-go" +) + +// CommitCommand represents a CommitCommand. +type CommitCommand struct { + Meta +} + +// Synopsis returns a one-line synopsis. +func (c *CommitCommand) Synopsis() string { + return "Create a database from the structure of the MailData directory." +} + +// Help returns long-form help text. +func (c *CommitCommand) Help() string { + txt := fmt.Sprintf(` +Usage: + %s %s + +Description: + Create a database from the structure of the MailData directory. +`, + c.CmdName, c.SubCmdName) + + return txt[1:] +} + +// Run runs the command and returns the exit status. +func (c *CommitCommand) Run(args []string) int { + repo, err := mailfull.OpenRepository(".") + if err != nil { + fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err) + return 1 + } + + mailData, err := repo.MailData() + if err != nil { + fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err) + return 1 + } + + err = repo.GenerateDatabases(mailData) + if err != nil { + fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err) + return 1 + } + + return 0 +} diff --git a/cmd/mailfull/main.go b/cmd/mailfull/main.go index 8bff108..9c48eee 100644 --- a/cmd/mailfull/main.go +++ b/cmd/mailfull/main.go @@ -47,6 +47,10 @@ func main() { meta.SubCmdName = c.Subcommand() return &command.DomainListCommand{Meta: meta}, nil }, + "commit": func() (cli.Command, error) { + meta.SubCmdName = c.Subcommand() + return &command.CommitCommand{Meta: meta}, nil + }, } exitCode, err := c.Run()