diff options
author | Daniel Bridges <bridges2@gmail.com> | 2019-08-12 06:15:45 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-08-13 10:49:34 +0900 |
commit | 72204d1f24d4082acc750b73dcda6981edd21a38 (patch) | |
tree | 76a2d79320ec2da88762d28ef66a391243206543 /commands | |
parent | 5493af8c8f13ab3b6ab4caab4d00189b49d7f50f (diff) |
Add optional body argument to compose command
Diffstat (limited to 'commands')
-rw-r--r-- | commands/account/compose.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go index fa673f0..a4836b7 100644 --- a/commands/account/compose.go +++ b/commands/account/compose.go @@ -1,6 +1,7 @@ package account import ( + "errors" "regexp" "strings" @@ -22,7 +23,6 @@ func (_ Compose) Complete(aerc *widgets.Aerc, args []string) []string { return nil } -// TODO: Accept arguments for message body func (_ Compose) Execute(aerc *widgets.Aerc, args []string) error { body, err := buildBody(args) if err != nil { @@ -46,7 +46,7 @@ func (_ Compose) Execute(aerc *widgets.Aerc, args []string) error { func buildBody(args []string) (string, error) { var body, headers string - opts, _, err := getopt.Getopts(args, "H:") + opts, optind, err := getopt.Getopts(args, "H:") if err != nil { return "", err } @@ -62,8 +62,19 @@ func buildBody(args []string) (string, error) { } } } + posargs := args[optind:] + if len(posargs) > 1 { + return "", errors.New("Usage: compose [-H] [body]") + } + if len(posargs) == 1 { + body = posargs[0] + } if headers != "" { - body = headers + "\n\n" + if len(body) > 0 { + body = headers + "\n" + body + } else { + body = headers + "\n\n" + } } return body, nil } |