mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-17 17:47:04 +00:00
Implement to generate configuration for postfix/dovecot #6
This commit is contained in:
67
cmd/mailfull/command/genconfig.go
Normal file
67
cmd/mailfull/command/genconfig.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/directorz/mailfull-go"
|
||||
)
|
||||
|
||||
// GenConfigCommand represents a GenConfigCommand.
|
||||
type GenConfigCommand struct {
|
||||
Meta
|
||||
}
|
||||
|
||||
// Synopsis returns a one-line synopsis.
|
||||
func (c *GenConfigCommand) Synopsis() string {
|
||||
return "Write a Postfix or Dovecot configuration to stdout."
|
||||
}
|
||||
|
||||
// Help returns long-form help text.
|
||||
func (c *GenConfigCommand) Help() string {
|
||||
txt := fmt.Sprintf(`
|
||||
Usage:
|
||||
%s %s name
|
||||
|
||||
Description:
|
||||
%s
|
||||
|
||||
Required Args:
|
||||
name
|
||||
The software name that you want to generate a configuration.
|
||||
Available names are "postfix" and "dovecot".
|
||||
`,
|
||||
c.CmdName, c.SubCmdName,
|
||||
c.Synopsis())
|
||||
|
||||
return txt[1:]
|
||||
}
|
||||
|
||||
// Run runs the command and returns the exit status.
|
||||
func (c *GenConfigCommand) Run(args []string) int {
|
||||
if len(args) != 1 {
|
||||
fmt.Fprintf(c.UI.ErrorWriter, "%v\n", c.Help())
|
||||
return 1
|
||||
}
|
||||
|
||||
softwareName := args[0]
|
||||
|
||||
repo, err := mailfull.OpenRepository(".")
|
||||
if err != nil {
|
||||
fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
switch softwareName {
|
||||
case "postfix":
|
||||
fmt.Fprintf(c.UI.Writer, "%s", repo.GenerateConfigPostfix())
|
||||
|
||||
case "dovecot":
|
||||
fmt.Fprintf(c.UI.Writer, "%s", repo.GenerateConfigDovecot())
|
||||
|
||||
default:
|
||||
fmt.Fprintf(c.UI.ErrorWriter, "[ERR] Specify \"postfix\" or \"dovecot\".\n")
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user