cmd/status.go
changeset 15 8ac069eaa817
parent 13 f862af8faf17
child 20 b0ccc09f07a2
--- a/cmd/status.go	Mon Apr 24 22:30:07 2017 +0200
+++ b/cmd/status.go	Mon Apr 24 23:05:27 2017 +0200
@@ -7,6 +7,7 @@
 
 import (
 	"errors"
+	"io/ioutil"
 	"strings"
 
 	"github.com/spf13/cobra"
@@ -19,12 +20,13 @@
 	unset    bool
 
 	// The following fields are used for the post/toot command
-	visibility  string
-	sensitive   bool
-	spoiler     string
-	inReplyToID int
-	filePath    string
-	mediaIDs    string
+	visibility    string
+	sensitive     bool
+	spoiler       string
+	inReplyToID   int
+	mediaIDs      string
+	mediaFilePath string
+	textFilePath  string
 
 	// Used for several subcommands to limit the number of results
 	limit uint
@@ -49,7 +51,8 @@
 	statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)")
 	statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)")
 	statusPostSubcommand.Flags().StringVar(&statusOpts.mediaIDs, "media-ids", "", "Comma-separated list of media IDs")
-	statusPostSubcommand.Flags().StringVarP(&statusOpts.filePath, "file", "f", "", "File name")
+	statusPostSubcommand.Flags().StringVarP(&statusOpts.mediaFilePath, "file", "f", "", "Media file name")
+	statusPostSubcommand.Flags().StringVar(&statusOpts.textFilePath, "text-file", "", "Text file name (message content)")
 	statusPostSubcommand.Flags().IntVarP(&statusOpts.inReplyToID, "in-reply-to", "r", 0, "Status ID to reply to")
 }
 
@@ -147,7 +150,8 @@
 	Short:   "Post a message (same as 'madonctl toot')",
 	Example: `  madonctl status post --spoiler Warning "Hello, World"
   madonctl status toot --sensitive --file image.jpg Image
-  madonctl status post --media-ids ID1,ID2,ID3 Image`,
+  madonctl status post --media-ids ID1,ID2,ID3 Image
+  madonctl status toot --text-file message.txt`,
 	RunE: func(cmd *cobra.Command, args []string) error {
 		return statusSubcommandRunE(cmd.Name(), args)
 	},
@@ -202,7 +206,15 @@
 		}
 	case "post": // toot
 		var s *madon.Status
-		s, err = toot(strings.Join(args, " "))
+		text := strings.Join(args, " ")
+		if opt.textFilePath != "" {
+			var b []byte
+			if b, err = ioutil.ReadFile(opt.textFilePath); err != nil {
+				break
+			}
+			text = string(b)
+		}
+		s, err = toot(text)
 		obj = s
 	default:
 		return errors.New("statusSubcommand: internal error")