1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-21 03:27:02 +00:00

Integrate subpackage

This commit is contained in:
teru
2017-07-25 11:19:25 +09:00
parent 2bb46731d0
commit 552ed95a0f
25 changed files with 48 additions and 49 deletions

View File

@@ -0,0 +1,66 @@
package main
import (
"fmt"
"sort"
"github.com/directorz/mailfull-go"
)
// AliasUsersCommand represents a AliasUsersCommand.
type AliasUsersCommand struct {
Meta
}
// Synopsis returns a one-line synopsis.
func (c *AliasUsersCommand) Synopsis() string {
return "Show aliasusers."
}
// Help returns long-form help text.
func (c *AliasUsersCommand) Help() string {
txt := fmt.Sprintf(`
Usage:
%s %s domain
Description:
%s
Required Args:
domain
The domain name.
`,
c.CmdName, c.SubCmdName,
c.Synopsis())
return txt[1:]
}
// Run runs the command and returns the exit status.
func (c *AliasUsersCommand) Run(args []string) int {
if len(args) != 1 {
fmt.Fprintf(c.UI.ErrorWriter, "%v\n", c.Help())
return 1
}
targetDomainName := args[0]
repo, err := mailfull.OpenRepository(".")
if err != nil {
fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err)
return 1
}
aliasUsers, err := repo.AliasUsers(targetDomainName)
if err != nil {
fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err)
return 1
}
sort.Sort(mailfull.AliasUserSlice(aliasUsers))
for _, aliasUser := range aliasUsers {
fmt.Fprintf(c.UI.Writer, "%s\n", aliasUser.Name())
}
return 0
}