37 |
37 |
38 // Used for several subcommands to limit the number of results |
38 // Used for several subcommands to limit the number of results |
39 limit, keep uint |
39 limit, keep uint |
40 //sinceID, maxID int64 |
40 //sinceID, maxID int64 |
41 all bool |
41 all bool |
|
42 |
|
43 // Used to indicate whether `in-reply-to` flag is present or not. |
|
44 _hasReplyTo bool |
42 } |
45 } |
43 |
46 |
44 func init() { |
47 func init() { |
45 RootCmd.AddCommand(statusCmd) |
48 RootCmd.AddCommand(statusCmd) |
46 |
49 |
47 // Subcommands |
50 // Subcommands |
48 statusCmd.AddCommand(statusSubcommands...) |
51 statusCmd.AddCommand(statusSubcommands...) |
49 |
52 |
50 // Global flags |
53 // Global flags |
51 statusCmd.PersistentFlags().Int64VarP(&statusOpts.statusID, "status-id", "s", 0, "Status ID number") |
54 statusCmd.PersistentFlags().StringVarP(&statusOpts.statusID, "status-id", "s", "", "Status ID number") |
52 statusCmd.PersistentFlags().UintVarP(&statusOpts.limit, "limit", "l", 0, "Limit number of API results") |
55 statusCmd.PersistentFlags().UintVarP(&statusOpts.limit, "limit", "l", 0, "Limit number of API results") |
53 statusCmd.PersistentFlags().UintVarP(&statusOpts.keep, "keep", "k", 0, "Limit number of results") |
56 statusCmd.PersistentFlags().UintVarP(&statusOpts.keep, "keep", "k", 0, "Limit number of results") |
54 //statusCmd.PersistentFlags().Int64Var(&statusOpts.sinceID, "since-id", 0, "Request IDs greater than a value") |
57 //statusCmd.PersistentFlags().Int64Var(&statusOpts.sinceID, "since-id", 0, "Request IDs greater than a value") |
55 //statusCmd.PersistentFlags().Int64Var(&statusOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value") |
58 //statusCmd.PersistentFlags().Int64Var(&statusOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value") |
56 statusCmd.PersistentFlags().BoolVar(&statusOpts.all, "all", false, "Fetch all results (for reblogged-by/favourited-by)") |
59 statusCmd.PersistentFlags().BoolVar(&statusOpts.all, "all", false, "Fetch all results (for reblogged-by/favourited-by)") |
63 statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)") |
66 statusPostSubcommand.Flags().StringVar(&statusOpts.visibility, "visibility", "", "Visibility (direct|private|unlisted|public)") |
64 statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)") |
67 statusPostSubcommand.Flags().StringVar(&statusOpts.spoiler, "spoiler", "", "Spoiler warning (CW)") |
65 statusPostSubcommand.Flags().StringVar(&statusOpts.mediaIDs, "media-ids", "", "Comma-separated list of media IDs") |
68 statusPostSubcommand.Flags().StringVar(&statusOpts.mediaIDs, "media-ids", "", "Comma-separated list of media IDs") |
66 statusPostSubcommand.Flags().StringVarP(&statusOpts.mediaFilePath, "file", "f", "", "Media file name") |
69 statusPostSubcommand.Flags().StringVarP(&statusOpts.mediaFilePath, "file", "f", "", "Media file name") |
67 statusPostSubcommand.Flags().StringVar(&statusOpts.textFilePath, "text-file", "", "Text file name (message content)") |
70 statusPostSubcommand.Flags().StringVar(&statusOpts.textFilePath, "text-file", "", "Text file name (message content)") |
68 statusPostSubcommand.Flags().Int64VarP(&statusOpts.inReplyToID, "in-reply-to", "r", 0, "Status ID to reply to") |
71 statusPostSubcommand.Flags().StringVarP(&statusOpts.inReplyToID, "in-reply-to", "r", "", "Status ID to reply to") |
69 statusPostSubcommand.Flags().BoolVar(&statusOpts.stdin, "stdin", false, "Read message content from standard input") |
72 statusPostSubcommand.Flags().BoolVar(&statusOpts.stdin, "stdin", false, "Read message content from standard input") |
70 statusPostSubcommand.Flags().BoolVar(&statusOpts.addMentions, "add-mentions", false, "Add mentions when replying") |
73 statusPostSubcommand.Flags().BoolVar(&statusOpts.addMentions, "add-mentions", false, "Add mentions when replying") |
71 statusPostSubcommand.Flags().BoolVar(&statusOpts.sameVisibility, "same-visibility", false, "Use same visibility as original message (for replies)") |
74 statusPostSubcommand.Flags().BoolVar(&statusOpts.sameVisibility, "same-visibility", false, "Use same visibility as original message (for replies)") |
72 |
75 |
73 // Deprecated flags |
76 // Deprecated flags |
92 Aliases: []string{"st"}, |
95 Aliases: []string{"st"}, |
93 Short: "Get status details", |
96 Short: "Get status details", |
94 //Long: `TBW...`, // TODO |
97 //Long: `TBW...`, // TODO |
95 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
98 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
96 // This is common to status and all status subcommands but "post" |
99 // This is common to status and all status subcommands but "post" |
97 if statusOpts.statusID < 1 && cmd.Name() != "post" { |
100 if statusOpts.statusID == "" && cmd.Name() != "post" { |
98 return errors.New("missing status ID") |
101 return errors.New("missing status ID") |
99 } |
102 } |
100 return madonInit(true) |
103 return madonInit(true) |
101 }, |
104 }, |
102 } |
105 } |
239 echo "Hello from #madonctl" | madonctl status toot --stdin |
242 echo "Hello from #madonctl" | madonctl status toot --stdin |
240 |
243 |
241 The default visibility can be set in the configuration file with the option |
244 The default visibility can be set in the configuration file with the option |
242 'default_visibility' (or with an environmnent variable).`, |
245 'default_visibility' (or with an environmnent variable).`, |
243 RunE: func(cmd *cobra.Command, args []string) error { |
246 RunE: func(cmd *cobra.Command, args []string) error { |
|
247 // Update the extra flag to reflect if `in-reply-to` was present or not |
|
248 statusOpts._hasReplyTo = cmd.Flags().Lookup("in-reply-to").Changed |
244 return statusSubcommandRunE(cmd.Name(), args) |
249 return statusSubcommandRunE(cmd.Name(), args) |
245 }, |
250 }, |
246 } |
251 } |
247 |
252 |
248 func statusSubcommandRunE(subcmd string, args []string) error { |
253 func statusSubcommandRunE(subcmd string, args []string) error { |