1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-18 18:17:03 +00:00
Files
mailfull-go/cmd/mailfull/command/commit.go
2016-08-01 17:08:49 +09:00

55 lines
1.0 KiB
Go

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
}