Skip to content

Commit

Permalink
Fix #2 - magically support posix and go flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-kent committed Jun 1, 2015
1 parent c88cf12 commit 68340da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
VERSION=0.1.8
VERSION=0.1.9

all: release
all: deps release

deps:
go get github.com/ogier/pflag

release: release-deps
gox -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" .
Expand Down
31 changes: 27 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ import (
"net/smtp"
"os"
"os/user"
"strings"

"github.com/ogier/pflag"
)

func Go() {
smtpAddr := "localhost:1025"

goflag := false
for _, g := range os.Args[1:] {
if strings.HasPrefix(g, "-") && !strings.HasPrefix(g, "--") {
if strings.HasPrefix(g, "-from ") || strings.HasPrefix(g, "-from=") ||
strings.HasPrefix(g, "-smtp-addr ") || strings.HasPrefix(g, "-smtp-addr=") {
goflag = true
break
}
}
}

host, err := os.Hostname()
if err != nil {
host = "localhost"
Expand All @@ -25,13 +39,22 @@ func Go() {
}

fromAddr := username + "@" + host
var recip []string

flag.StringVar(&smtpAddr, "smtp-addr", smtpAddr, "SMTP server address")
flag.StringVar(&fromAddr, "from", fromAddr, "SMTP sender")
if goflag {
flag.StringVar(&smtpAddr, "smtp-addr", smtpAddr, "SMTP server address")
flag.StringVar(&fromAddr, "from", fromAddr, "SMTP sender")

flag.Parse()
flag.Parse()
recip = flag.Args()
} else {
pflag.StringVar(&smtpAddr, "smtp-addr", smtpAddr, "SMTP server address")
pflag.StringVarP(&fromAddr, "from", "f", fromAddr, "SMTP sender")

pflag.Parse()
recip = pflag.Args()
}

recip := flag.Args()
if len(recip) == 0 {
fmt.Fprintln(os.Stderr, "missing recipient")
os.Exit(10)
Expand Down

0 comments on commit 68340da

Please sign in to comment.