equal
deleted
inserted
replaced
16 ) |
16 ) |
17 |
17 |
18 var mediaFlags *flag.FlagSet |
18 var mediaFlags *flag.FlagSet |
19 |
19 |
20 var mediaOpts struct { |
20 var mediaOpts struct { |
21 mediaID int64 |
21 mediaID madon.ActivityID |
22 filePath string |
22 filePath string |
23 description string |
23 description string |
24 focus string |
24 focus string |
25 } |
25 } |
26 |
26 |
46 |
46 |
47 func init() { |
47 func init() { |
48 RootCmd.AddCommand(mediaCmd) |
48 RootCmd.AddCommand(mediaCmd) |
49 |
49 |
50 mediaCmd.Flags().StringVar(&mediaOpts.filePath, "file", "", "Path of the media file") |
50 mediaCmd.Flags().StringVar(&mediaOpts.filePath, "file", "", "Path of the media file") |
51 mediaCmd.Flags().Int64Var(&mediaOpts.mediaID, "update", 0, "Media to update (ID)") |
51 mediaCmd.Flags().StringVar(&mediaOpts.mediaID, "update", "", "Media to update (ID)") |
52 |
52 |
53 mediaCmd.Flags().StringVar(&mediaOpts.description, "description", "", "Plain text description") |
53 mediaCmd.Flags().StringVar(&mediaOpts.description, "description", "", "Plain text description") |
54 mediaCmd.Flags().StringVar(&mediaOpts.focus, "focus", "", "Focal point") |
54 mediaCmd.Flags().StringVar(&mediaOpts.focus, "focus", "", "Focal point") |
55 |
55 |
56 // This will be used to check if the options were explicitly set or not |
56 // This will be used to check if the options were explicitly set or not |
59 |
59 |
60 func mediaRunE(cmd *cobra.Command, args []string) error { |
60 func mediaRunE(cmd *cobra.Command, args []string) error { |
61 opt := mediaOpts |
61 opt := mediaOpts |
62 |
62 |
63 if opt.filePath == "" { |
63 if opt.filePath == "" { |
64 if opt.mediaID < 1 { |
64 if opt.mediaID == "" { |
65 return errors.New("no media file name provided") |
65 return errors.New("no media file name provided") |
66 } |
66 } |
67 } else if opt.mediaID > 0 { |
67 } else if opt.mediaID != "" { |
68 return errors.New("cannot use both --file and --update") |
68 return errors.New("cannot use both --file and --update") |
69 } |
69 } |
70 |
70 |
71 if err := madonInit(true); err != nil { |
71 if err := madonInit(true); err != nil { |
72 return err |
72 return err |
100 } |
100 } |
101 return p.printObj(attachment) |
101 return p.printObj(attachment) |
102 } |
102 } |
103 |
103 |
104 // uploadFile uploads a media file and returns the attachment ID |
104 // uploadFile uploads a media file and returns the attachment ID |
105 func uploadFile(filePath string) (int64, error) { |
105 func uploadFile(filePath string) (madon.ActivityID, error) { |
106 attachment, err := gClient.UploadMedia(filePath, "", "") |
106 attachment, err := gClient.UploadMedia(filePath, "", "") |
107 if err != nil { |
107 if err != nil { |
108 return 0, err |
108 return "", err |
109 } |
109 } |
110 if attachment == nil { |
110 if attachment == nil { |
111 return 0, nil |
111 return "", nil |
112 } |
112 } |
113 return attachment.ID, nil |
113 return attachment.ID, nil |
114 } |
114 } |