Skip to content

Commit

Permalink
Deprecate composeform command (use compose instead)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhpedersen committed Dec 13, 2024
1 parent 855c867 commit 8145400
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
31 changes: 19 additions & 12 deletions cli_composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func composeMessage(ctx context.Context, args []string) {
attachments := set.StringArrayP("attachment", "a", nil, "")
ccs := set.StringArrayP("cc", "c", nil, "")
p2pOnly := set.BoolP("p2p-only", "", false, "")
template := set.StringP("template", "", "", "")
set.Parse(args)

// Remaining args are recipients
Expand All @@ -120,13 +121,20 @@ func composeMessage(ctx context.Context, args []string) {
recipients = append(recipients, r)
}

// Check if any args are set. If so, go non-interactive
// Otherwise, interactive
if (len(*subject) + len(*attachments) + len(*ccs) + len(recipients)) > 0 {
// Check if condition are met for non-interactive compose.
if (len(*subject)+len(*attachments)+len(*ccs)+len(recipients)) > 0 && *template != "" {
noninteractiveComposeMessage(*from, *subject, *attachments, *ccs, recipients, *p2pOnly)
} else {
interactiveComposeMessage(nil)
return
}

// Use template?
if *template != "" {
interactiveComposeWithTemplate(*template, nil)
return
}

// Interactive compose
interactiveComposeMessage(nil)
}

func noninteractiveComposeMessage(from string, subject string, attachments []string, ccs []string, recipients []string, p2pOnly bool) {
Expand Down Expand Up @@ -254,15 +262,14 @@ func readLine() string {
}

func composeFormReport(ctx context.Context, args []string) {
var tmplPathArg string

set := pflag.NewFlagSet("form", pflag.ExitOnError)
set.StringVar(&tmplPathArg, "template", "ICS USA Forms/ICS213", "")
set.Parse(args)
log.Println("DEPRECATED: Use `compose --template` instead")
composeMessage(ctx, args)
}

msg := composeMessageHeader(nil)
func interactiveComposeWithTemplate(template string, replyTo *fbb.Message) {
msg := composeMessageHeader(replyTo)

formMsg, err := formsMgr.ComposeTemplate(tmplPathArg, msg.Subject())
formMsg, err := formsMgr.ComposeTemplate(template, msg.Subject())
if err != nil {
log.Printf("failed to compose message for template: %v", err)
return
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var commands = []Command{
"\tIf options are passed, reads message from stdin similar to mail(1).",
Options: map[string]string{
"--from, -r": "Address to send from. Default is your call from config or --mycall, but can be specified to use tactical addresses.",
"--template": "Compose using template file. Uses the --forms directory as root for relative paths.",
"--subject, -s": "Subject",
"--attachment , -a": "Attachment path (may be repeated)",
"--cc, -c": "CC Address(es) (may be repeated)",
Expand All @@ -106,7 +107,7 @@ var commands = []Command{
{
Str: "composeform",
Aliases: []string{"formPath"},
Desc: "Post form-based report.",
Desc: "Post form-based report. (DEPRECATED)",
Usage: "[options]",
Options: map[string]string{
"--template": "path to the form template file. Uses the --forms directory as root. Defaults to 'ICS USA Forms/ICS213.txt'",
Expand Down

0 comments on commit 8145400

Please sign in to comment.