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:
54
cmd/mailfull/command/commit.go
Normal file
54
cmd/mailfull/command/commit.go
Normal 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
|
||||||
|
}
|
||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user