mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-18 10:07:03 +00:00
Move Meta to cmd package
This commit is contained in:
@@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
mailfull "github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasDomainAdd represents a CmdAliasDomainAdd.
|
// CmdAliasDomainAdd represents a CmdAliasDomainAdd.
|
||||||
type CmdAliasDomainAdd struct {
|
type CmdAliasDomainAdd struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
mailfull "github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasDomainDel represents a CmdAliasDomainDel.
|
// CmdAliasDomainDel represents a CmdAliasDomainDel.
|
||||||
type CmdAliasDomainDel struct {
|
type CmdAliasDomainDel struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
mailfull "github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasDomains represents a CmdAliasDomains.
|
// CmdAliasDomains represents a CmdAliasDomains.
|
||||||
type CmdAliasDomains struct {
|
type CmdAliasDomains struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
mailfull "github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasUserAdd represents a CmdAliasUserAdd.
|
// CmdAliasUserAdd represents a CmdAliasUserAdd.
|
||||||
type CmdAliasUserAdd struct {
|
type CmdAliasUserAdd struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
mailfull "github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasUserDel represents a CmdAliasUserDel.
|
// CmdAliasUserDel represents a CmdAliasUserDel.
|
||||||
type CmdAliasUserDel struct {
|
type CmdAliasUserDel struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
mailfull "github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasUserMod represents a CmdAliasUserMod.
|
// CmdAliasUserMod represents a CmdAliasUserMod.
|
||||||
type CmdAliasUserMod struct {
|
type CmdAliasUserMod struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdAliasUsers represents a CmdAliasUsers.
|
// CmdAliasUsers represents a CmdAliasUsers.
|
||||||
type CmdAliasUsers struct {
|
type CmdAliasUsers struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdCatchAll represents a CmdCatchAll.
|
// CmdCatchAll represents a CmdCatchAll.
|
||||||
type CmdCatchAll struct {
|
type CmdCatchAll struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdCatchAllSet represents a CmdCatchAllSet.
|
// CmdCatchAllSet represents a CmdCatchAllSet.
|
||||||
type CmdCatchAllSet struct {
|
type CmdCatchAllSet struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdCatchAllUnset represents a CmdCatchAllUnset.
|
// CmdCatchAllUnset represents a CmdCatchAllUnset.
|
||||||
type CmdCatchAllUnset struct {
|
type CmdCatchAllUnset struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdCommit represents a CmdCommit.
|
// CmdCommit represents a CmdCommit.
|
||||||
type CmdCommit struct {
|
type CmdCommit struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDomainAdd represents a CmdDomainAdd.
|
// CmdDomainAdd represents a CmdDomainAdd.
|
||||||
type CmdDomainAdd struct {
|
type CmdDomainAdd struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDomainDel represents a CmdDomainDel.
|
// CmdDomainDel represents a CmdDomainDel.
|
||||||
type CmdDomainDel struct {
|
type CmdDomainDel struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDomainDisable represents a CmdDomainDisable.
|
// CmdDomainDisable represents a CmdDomainDisable.
|
||||||
type CmdDomainDisable struct {
|
type CmdDomainDisable struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDomainEnable represents a CmdDomainEnable.
|
// CmdDomainEnable represents a CmdDomainEnable.
|
||||||
type CmdDomainEnable struct {
|
type CmdDomainEnable struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDomains represents a CmdDomains.
|
// CmdDomains represents a CmdDomains.
|
||||||
type CmdDomains struct {
|
type CmdDomains struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdGenConfig represents a CmdGenConfig.
|
// CmdGenConfig represents a CmdGenConfig.
|
||||||
type CmdGenConfig struct {
|
type CmdGenConfig struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdInit represents a CmdInit.
|
// CmdInit represents a CmdInit.
|
||||||
type CmdInit struct {
|
type CmdInit struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdUserAdd represents a CmdUserAdd.
|
// CmdUserAdd represents a CmdUserAdd.
|
||||||
type CmdUserAdd struct {
|
type CmdUserAdd struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
"github.com/jsimonetti/pwscheme/ssha"
|
"github.com/jsimonetti/pwscheme/ssha"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdUserCheckPw represents a CmdUserCheckPw.
|
// CmdUserCheckPw represents a CmdUserCheckPw.
|
||||||
type CmdUserCheckPw struct {
|
type CmdUserCheckPw struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdUserDel represents a CmdUserDel.
|
// CmdUserDel represents a CmdUserDel.
|
||||||
type CmdUserDel struct {
|
type CmdUserDel struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
"github.com/jsimonetti/pwscheme/ssha"
|
"github.com/jsimonetti/pwscheme/ssha"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdUserPasswd represents a CmdUserPasswd.
|
// CmdUserPasswd represents a CmdUserPasswd.
|
||||||
type CmdUserPasswd struct {
|
type CmdUserPasswd struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdUsers represents a CmdUsers.
|
// CmdUsers represents a CmdUsers.
|
||||||
type CmdUsers struct {
|
type CmdUsers struct {
|
||||||
Meta
|
cmd.Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis returns a one-line synopsis.
|
// Synopsis returns a one-line synopsis.
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ Command mailfull is a CLI application using the mailfull package.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/directorz/mailfull-go"
|
"github.com/directorz/mailfull-go"
|
||||||
|
"github.com/directorz/mailfull-go/cmd"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +33,7 @@ func main() {
|
|||||||
Args: os.Args[1:],
|
Args: os.Args[1:],
|
||||||
}
|
}
|
||||||
|
|
||||||
meta := Meta{
|
meta := cmd.Meta{
|
||||||
UI: &cli.BasicUi{
|
UI: &cli.BasicUi{
|
||||||
Reader: os.Stdin,
|
Reader: os.Stdin,
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
@@ -142,3 +145,17 @@ func main() {
|
|||||||
|
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noCommitFlag returns true if `pargs` has "-n" flag.
|
||||||
|
// `pargs` is overwrites with non-flag arguments.
|
||||||
|
func noCommitFlag(pargs *[]string) (bool, error) {
|
||||||
|
nFlag := false
|
||||||
|
|
||||||
|
flagSet := flag.NewFlagSet("", flag.ContinueOnError)
|
||||||
|
flagSet.SetOutput(&bytes.Buffer{})
|
||||||
|
flagSet.BoolVar(&nFlag, "n", nFlag, "")
|
||||||
|
err := flagSet.Parse(*pargs)
|
||||||
|
*pargs = flagSet.Args()
|
||||||
|
|
||||||
|
return nFlag, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"flag"
|
|
||||||
|
|
||||||
"github.com/mitchellh/cli"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Meta is for `*Command` struct.
|
|
||||||
type Meta struct {
|
|
||||||
UI *cli.BasicUi
|
|
||||||
CmdName string
|
|
||||||
SubCmdName string
|
|
||||||
Version string
|
|
||||||
}
|
|
||||||
|
|
||||||
// noCommitFlag returns true if `pargs` has "-n" flag.
|
|
||||||
// `pargs` is overwrites with non-flag arguments.
|
|
||||||
func noCommitFlag(pargs *[]string) (bool, error) {
|
|
||||||
nFlag := false
|
|
||||||
|
|
||||||
flagSet := flag.NewFlagSet("", flag.ContinueOnError)
|
|
||||||
flagSet.SetOutput(&bytes.Buffer{})
|
|
||||||
flagSet.BoolVar(&nFlag, "n", nFlag, "")
|
|
||||||
err := flagSet.Parse(*pargs)
|
|
||||||
*pargs = flagSet.Args()
|
|
||||||
|
|
||||||
return nFlag, err
|
|
||||||
}
|
|
||||||
20
cmd/meta.go
Normal file
20
cmd/meta.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/mitchellh/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Meta contains options to execute a command.
|
||||||
|
type Meta struct {
|
||||||
|
UI *cli.BasicUi
|
||||||
|
CmdName string
|
||||||
|
SubCmdName string
|
||||||
|
Version string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf prints the error to ErrorWriter with the prefix string.
|
||||||
|
func (m Meta) Errorf(format string, v ...interface{}) {
|
||||||
|
fmt.Fprintf(m.UI.ErrorWriter, "[ERR] "+format, v...)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user