cmd/status.go
changeset 267 5b91a65ba95a
parent 239 605a00e9d1ab
child 268 4dd196a4ee7c
equal deleted inserted replaced
264:8f478162d991 267:5b91a65ba95a
    18 )
    18 )
    19 
    19 
    20 var statusPostFlags *flag.FlagSet
    20 var statusPostFlags *flag.FlagSet
    21 
    21 
    22 var statusOpts struct {
    22 var statusOpts struct {
    23 	statusID int64
    23 	statusID madon.ActivityID
    24 	unset    bool // TODO remove eventually?
    24 	unset    bool // TODO remove eventually?
    25 
    25 
    26 	// The following fields are used for the post/toot command
    26 	// The following fields are used for the post/toot command
    27 	visibility     string
    27 	visibility     string
    28 	sensitive      bool
    28 	sensitive      bool
    29 	spoiler        string
    29 	spoiler        string
    30 	inReplyToID    int64
    30 	inReplyToID    madon.ActivityID
    31 	mediaIDs       string
    31 	mediaIDs       string
    32 	mediaFilePath  string
    32 	mediaFilePath  string
    33 	textFilePath   string
    33 	textFilePath   string
    34 	stdin          bool
    34 	stdin          bool
    35 	addMentions    bool
    35 	addMentions    bool
    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 {