package main import ( "fmt" "github.com/directorz/mailfull-go" "github.com/directorz/mailfull-go/cmd" ) // CmdDomainDel represents a CmdDomainDel. type CmdDomainDel struct { cmd.Meta } // Synopsis returns a one-line synopsis. func (c *CmdDomainDel) Synopsis() string { return "Delete and backup a domain." } // Help returns long-form help text. func (c *CmdDomainDel) Help() string { txt := fmt.Sprintf(` Usage: %s %s [-n] domain Description: %s Required Args: domain The domain name that you want to delete. Optional Args: -n Don't update databases. `, c.CmdName, c.SubCmdName, c.Synopsis()) return txt[1:] } // Run runs the command and returns the exit status. func (c *CmdDomainDel) Run(args []string) int { noCommit, err := noCommitFlag(&args) if err != nil { fmt.Fprintf(c.UI.ErrorWriter, "%v\n", c.Help()) return 1 } if len(args) != 1 { fmt.Fprintf(c.UI.ErrorWriter, "%v\n", c.Help()) return 1 } domainName := args[0] repo, err := mailfull.OpenRepository(".") if err != nil { c.Meta.Errorf("%v\n", err) return 1 } if err := repo.DomainRemove(domainName); err != nil { c.Meta.Errorf("%v\n", err) return 1 } if noCommit { return 0 } if err = repo.GenerateDatabases(); err != nil { c.Meta.Errorf("%v\n", err) return 1 } return 0 }