Skip to content

Commit 381103a

Browse files
committed
Use Go toolbox, updated docs
- Make use of common code moved to the toolbox package - Updated installation instructions and fixed the root help output
1 parent 4851453 commit 381103a

22 files changed

Lines changed: 66 additions & 469 deletions

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@ The tool is currently only tested on Mac OS X systems, but should just work on o
1010

1111
## Installing
1212

13-
Installing Aliasman is easy. First, use `go get` to install the latest version
14-
of the application from GitHub. This command will install the `aliasman` executable in the Go path:
13+
### Directly From GitHub
1514

16-
go get -u github.com/aliasman/cmd/aliasman
15+
Installing aliasman is easy. First, use `go get` to install the latest version of the application
16+
from GitHub. This command will install the `aliasman` executable in the Go path:
17+
18+
go get -u github.com/patsoffice/aliasman
19+
20+
The above command requires a working [Go compiler installed](https://golang.org/doc/install).
21+
22+
### Homebrew
23+
24+
brew tap patsoffice/tools
25+
brew install aliasman
1726

1827
## Configuring
1928

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/mitchellh/go-homedir v1.1.0
2020
github.com/mitchellh/mapstructure v1.2.2 // indirect
2121
github.com/patsoffice/reago v0.0.0-20200328164243-566c8e8c6e4d
22+
github.com/patsoffice/toolbox v0.0.0-20200503001601-b719ff99c0d8
2223
github.com/pelletier/go-toml v1.6.0 // indirect
2324
github.com/pmezard/go-difflib v1.0.0
2425
github.com/spf13/afero v1.2.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
211211
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
212212
github.com/patsoffice/reago v0.0.0-20200328164243-566c8e8c6e4d h1:H2Nk5vJJMI4xqpcDfYi+l9YJ5y5GsAhBo55rjKRtrCM=
213213
github.com/patsoffice/reago v0.0.0-20200328164243-566c8e8c6e4d/go.mod h1:e8D1ij7jFejEUg+ntZzBSDyNX3EMMQdc5+d3dfiTYfk=
214+
github.com/patsoffice/toolbox v0.0.0-20200503001601-b719ff99c0d8 h1:plcsbSAPRs8omu7lA/u7yBnw+zwRm1EujQbSqjHsf9o=
215+
github.com/patsoffice/toolbox v0.0.0-20200503001601-b719ff99c0d8/go.mod h1:eZ/mepRzc2S6sEz1JDXIxLwIjHcmaxWcJ0WwCVNIXpM=
214216
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
215217
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
216218
github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=

internal/alias/alias.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"time"
2727

2828
"github.com/davecgh/go-spew/spew"
29-
"github.com/patsoffice/aliasman/internal/util"
29+
"github.com/patsoffice/toolbox"
3030
"github.com/pmezard/go-difflib/difflib"
3131
)
3232

@@ -41,7 +41,7 @@ func (a Alias) Equal(b Alias) bool {
4141
if !a.CreatedTS.Equal(b.CreatedTS) || !a.ModifiedTS.Equal(b.ModifiedTS) || !a.SuspendedTS.Equal(b.SuspendedTS) {
4242
return false
4343
}
44-
if !util.StringSliceEqual(a.EmailAddresses, b.EmailAddresses) {
44+
if !toolbox.StringSliceEqual(a.EmailAddresses, b.EmailAddresses) {
4545
return false
4646
}
4747
return true

internal/cmd/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
"github.com/patsoffice/aliasman/internal/email"
3131
"github.com/patsoffice/aliasman/internal/storage"
32-
"github.com/patsoffice/aliasman/internal/util"
32+
"github.com/patsoffice/toolbox"
3333
"github.com/spf13/cobra"
3434
"github.com/spf13/viper"
3535
)
@@ -61,15 +61,15 @@ func runInit(cmd *cobra.Command, args []string) {
6161

6262
scanner := bufio.NewScanner(os.Stdin)
6363

64-
if ok := util.CheckYes(scanner, "Set a default domain?", false); ok {
65-
defaultDomain := util.GetInputString(scanner, "Domain", viper.GetString("default_domain"))
64+
if ok := toolbox.CheckYes(scanner, "Set a default domain?", false); ok {
65+
defaultDomain := toolbox.GetInputString(scanner, "Domain", viper.GetString("default_domain"))
6666
viper.Set("default_domain", defaultDomain)
6767
}
6868

69-
if ok := util.CheckYes(scanner, "Set default email address(es)?", false); ok {
69+
if ok := toolbox.CheckYes(scanner, "Set default email address(es)?", false); ok {
7070
defaultEmails := strings.Join(viper.GetStringSlice("default_addresses"), ", ")
7171
for {
72-
defaultEmails = util.GetInputString(scanner, "Email addresses (comma separated)", defaultEmails)
72+
defaultEmails = toolbox.GetInputString(scanner, "Email addresses (comma separated)", defaultEmails)
7373
defaultEmails = strings.ReplaceAll(defaultEmails, " ", "")
7474
emails := strings.Split(defaultEmails, ",")
7575
if len(emails) == 0 {
@@ -83,15 +83,15 @@ func runInit(cmd *cobra.Command, args []string) {
8383

8484
cfgDir := DefaultDir()
8585
if !pathExists(cfgDir) {
86-
if ok := util.CheckYes(scanner, fmt.Sprintf("Create configuration directory: %s?", cfgDir), true); ok {
86+
if ok := toolbox.CheckYes(scanner, fmt.Sprintf("Create configuration directory: %s?", cfgDir), true); ok {
8787
if err := os.MkdirAll(rootFlags.cfgDir, os.ModeDir|0700); err != nil {
8888
ErrorExit(err, nil)
8989
}
9090
}
9191
}
9292

9393
cfgPath := filepath.Join(cfgDir, DefaultConfigFile())
94-
if ok := util.CheckYes(scanner, fmt.Sprintf("Write config file: %s?", cfgPath), true); ok {
94+
if ok := toolbox.CheckYes(scanner, fmt.Sprintf("Write config file: %s?", cfgPath), true); ok {
9595
viper.WriteConfigAs(cfgPath)
9696
}
9797
}

internal/cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ var (
3333
rootCmd = &cobra.Command{
3434
Use: "aliasman",
3535
Short: "aliasman is a tool for managing email aliases",
36-
Long: `Rackspace email allows for a large number of email aliases. The aliasman tool
37-
allows for the creation, read, update and delete of Rackspace email aliases.
36+
Long: `Rackspace email, GSuite and others allow for a large number of email aliases.
37+
The aliasman tool allows for the creation, read, update and delete of
38+
aliases with various service providers.
3839
`,
3940
}
4041
rootFlags = struct {

internal/cmd/sync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
"github.com/patsoffice/aliasman/internal/alias"
3030
"github.com/patsoffice/aliasman/internal/storage"
31-
"github.com/patsoffice/aliasman/internal/util"
31+
"github.com/patsoffice/toolbox"
3232
"github.com/spf13/cobra"
3333
"github.com/spf13/viper"
3434
)
@@ -130,9 +130,9 @@ func syncCmdRun(cmd *cobra.Command, args []string) {
130130
ok := false
131131
if !syncFlags.yes {
132132
if doCopy {
133-
ok = util.CheckYes(scanner, fmt.Sprintf("Add alias for %s@%s to %s?", v.Alias, v.Domain, destProvider.Type()), true)
133+
ok = toolbox.CheckYes(scanner, fmt.Sprintf("Add alias for %s@%s to %s?", v.Alias, v.Domain, destProvider.Type()), true)
134134
} else {
135-
ok = util.CheckYes(scanner, fmt.Sprintf("Update alias for %s@%s to %s: %s?", v.Alias, v.Domain, destProvider.Type(), uDiff), true)
135+
ok = toolbox.CheckYes(scanner, fmt.Sprintf("Update alias for %s@%s to %s: %s?", v.Alias, v.Domain, destProvider.Type(), uDiff), true)
136136
}
137137
}
138138

internal/cmd/syncFromEmail.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"regexp"
2828

2929
"github.com/patsoffice/aliasman/internal/alias"
30-
"github.com/patsoffice/aliasman/internal/util"
30+
"github.com/patsoffice/toolbox"
3131
"github.com/spf13/cobra"
3232
"github.com/spf13/viper"
3333
)
@@ -97,7 +97,7 @@ func syncFromEmailCmdRun(cmd *cobra.Command, args []string) {
9797
if _, ok := destMap[k]; !ok {
9898
yes := false
9999
if !syncFromEmailFlags.yes {
100-
yes = util.CheckYes(scanner, fmt.Sprintf("Add alias for %s@%s to %s?", v.Alias, v.Domain, sp.Type()), true)
100+
yes = toolbox.CheckYes(scanner, fmt.Sprintf("Add alias for %s@%s to %s?", v.Alias, v.Domain, sp.Type()), true)
101101
}
102102

103103
if yes || syncFromEmailFlags.yes {

internal/providers/gsuite/factory.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
"github.com/patsoffice/aliasman/internal/cmd"
3434
"github.com/patsoffice/aliasman/internal/email"
35-
"github.com/patsoffice/aliasman/internal/util"
35+
"github.com/patsoffice/toolbox"
3636
"github.com/spf13/viper"
3737
"golang.org/x/oauth2"
3838
"golang.org/x/oauth2/google"
@@ -60,7 +60,7 @@ func (cn *ConfigerNewer) getTokenFromWeb(config *oauth2.Config) (*oauth2.Token,
6060

6161
authURL := config.AuthCodeURL("state-token", oauth2.AccessTypeOffline)
6262
msg := "Go to the following link in your browser: \n\n%v\n\nthen type the authorization code"
63-
authCode := util.GetInputString(scanner, fmt.Sprintf(msg, authURL), "")
63+
authCode := toolbox.GetInputString(scanner, fmt.Sprintf(msg, authURL), "")
6464

6565
tok, err := config.Exchange(context.TODO(), authCode)
6666
if err != nil {
@@ -97,8 +97,8 @@ func (cn *ConfigerNewer) saveToken(path string, token *oauth2.Token) error {
9797
func (cn *ConfigerNewer) Config() error {
9898
scanner := bufio.NewScanner(os.Stdin)
9999

100-
if ok := util.CheckYes(scanner, "Configure gsuite provider", false); ok {
101-
credentiasPath := util.GetInputString(scanner, "GSuite credential path", viper.GetString("gsuite_credentials"))
100+
if ok := toolbox.CheckYes(scanner, "Configure gsuite provider", false); ok {
101+
credentiasPath := toolbox.GetInputString(scanner, "GSuite credential path", viper.GetString("gsuite_credentials"))
102102
b, err := ioutil.ReadFile(credentiasPath)
103103
if err != nil {
104104
return fmt.Errorf("Unable to read client secret file: %v", err)
@@ -109,7 +109,7 @@ func (cn *ConfigerNewer) Config() error {
109109
}
110110
viper.Set("gsuite_credentials,", credentiasPath)
111111

112-
tokenPath := util.GetInputString(scanner, "GSuite token path", viper.GetString("gsuite_token"))
112+
tokenPath := toolbox.GetInputString(scanner, "GSuite token path", viper.GetString("gsuite_token"))
113113
if tok, err := cn.tokenFromFile(tokenPath); err != nil {
114114
cmd.ErrorNoExit(err)
115115
if tok, err = cn.getTokenFromWeb(config); err != nil {
@@ -121,7 +121,7 @@ func (cn *ConfigerNewer) Config() error {
121121
}
122122
viper.Set("gsuite_token,", tokenPath)
123123

124-
if ok := util.CheckYes(scanner, "Make gsuite the default email provider?", true); ok {
124+
if ok := toolbox.CheckYes(scanner, "Make gsuite the default email provider?", true); ok {
125125
viper.Set("email_type", "gsuite")
126126
}
127127
}

internal/providers/gsuite/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"github.com/patsoffice/aliasman/internal/alias"
2727
"github.com/patsoffice/aliasman/internal/email"
28-
"github.com/patsoffice/aliasman/internal/util"
28+
"github.com/patsoffice/toolbox"
2929
admin "google.golang.org/api/admin/directory/v1"
3030
)
3131

@@ -41,7 +41,7 @@ type ConfigerNewer struct{}
4141
// Emailer implements the email provder methods for the rackspace_email_api.
4242
type Emailer struct {
4343
readOnly bool
44-
clock util.Clock
44+
clock toolbox.Clock
4545
aliases alias.AliasesMap
4646
srv *admin.Service
4747
ctx context.Context

0 commit comments

Comments
 (0)