1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-18 10:07:03 +00:00

Implement commit subcommand

This commit is contained in:
teru
2016-08-01 17:08:49 +09:00
parent 7ae2d1422b
commit dbc25edeb4
2 changed files with 58 additions and 0 deletions

View File

@@ -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
}

View File

@@ -47,6 +47,10 @@ func main() {
meta.SubCmdName = c.Subcommand() meta.SubCmdName = c.Subcommand()
return &command.DomainListCommand{Meta: meta}, nil 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() exitCode, err := c.Run()