mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-17 17:47:04 +00:00
Implement domainlist subcommand
This commit is contained in:
55
cmd/mailfull/command/domainlist.go
Normal file
55
cmd/mailfull/command/domainlist.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package command
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/directorz/mailfull-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DomainListCommand represents a DomainListCommand.
|
||||||
|
type DomainListCommand struct {
|
||||||
|
Meta
|
||||||
|
}
|
||||||
|
|
||||||
|
// Synopsis returns a one-line synopsis.
|
||||||
|
func (c *DomainListCommand) Synopsis() string {
|
||||||
|
return "Show all domains."
|
||||||
|
}
|
||||||
|
|
||||||
|
// Help returns long-form help text.
|
||||||
|
func (c *DomainListCommand) Help() string {
|
||||||
|
txt := fmt.Sprintf(`
|
||||||
|
Usage:
|
||||||
|
%s %s
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Show all domains.
|
||||||
|
`,
|
||||||
|
c.CmdName, c.SubCmdName)
|
||||||
|
|
||||||
|
return txt[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run runs the command and returns the exit status.
|
||||||
|
func (c *DomainListCommand) Run(args []string) int {
|
||||||
|
repo, err := mailfull.OpenRepository(".")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
domains, err := repo.Domains()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(c.UI.ErrorWriter, "[ERR] %v\n", err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(mailfull.DomainSlice(domains))
|
||||||
|
|
||||||
|
for _, domain := range domains {
|
||||||
|
fmt.Fprintf(c.UI.Writer, "%s\n", domain.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -43,6 +43,10 @@ func main() {
|
|||||||
meta.SubCmdName = c.Subcommand()
|
meta.SubCmdName = c.Subcommand()
|
||||||
return &command.InitCommand{Meta: meta}, nil
|
return &command.InitCommand{Meta: meta}, nil
|
||||||
},
|
},
|
||||||
|
"domainlist": func() (cli.Command, error) {
|
||||||
|
meta.SubCmdName = c.Subcommand()
|
||||||
|
return &command.DomainListCommand{Meta: meta}, nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
exitCode, err := c.Run()
|
exitCode, err := c.Run()
|
||||||
|
|||||||
Reference in New Issue
Block a user