author | Mikael Berthe <mikael@lilotux.net> |
Sat, 04 Feb 2023 13:35:58 +0100 | |
changeset 271 | c8b8b7cc8896 |
parent 268 | 4dd196a4ee7c |
permissions | -rw-r--r-- |
265
05c40b36d3b2
Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents:
239
diff
changeset
|
1 |
// Copyright © 2018-2023 Mikael Berthe <mikael@lilotux.net> |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
2 |
// |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
3 |
// Licensed under the MIT license. |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
4 |
// Please see the LICENSE file is this directory. |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
5 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
6 |
package cmd |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
7 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
8 |
import ( |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
9 |
"os" |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
11 |
"github.com/pkg/errors" |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
12 |
"github.com/spf13/cobra" |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
13 |
|
265
05c40b36d3b2
Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents:
239
diff
changeset
|
14 |
"github.com/McKael/madon/v3" |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
15 |
) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
16 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
17 |
var listsOpts struct { |
267 | 18 |
listID madon.ActivityID |
19 |
accountID madon.ActivityID |
|
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
20 |
accountIDs string |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
21 |
title string |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
22 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
23 |
// Used for several subcommands to limit the number of results |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
24 |
limit, keep uint |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
25 |
all bool |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
26 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
|
265
05c40b36d3b2
Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents:
239
diff
changeset
|
28 |
// listsCmd represents the lists command |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 |
var listsCmd = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
30 |
Use: "lists", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
31 |
Aliases: []string{"list"}, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
32 |
Short: "Manage lists", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
33 |
Example: ` madonctl lists create --title "Friends" |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
34 |
madonctl lists show |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
35 |
madonctl lists show --list-id 3 |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
36 |
madonctl lists update --list-id 3 --title "Family" |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
37 |
madonctl lists delete --list-id 3 |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
38 |
madonctl lists accounts --list-id 2 |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
39 |
madonctl lists add-accounts --list-id 2 --account-ids 123,456 |
189
280fc76acf39
Add a "madonctl lists show" example
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
40 |
madonctl lists remove-accounts --list-id 2 --account-ids 456 |
280fc76acf39
Add a "madonctl lists show" example
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
41 |
madonctl lists show --account-id 123`, |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
42 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
43 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
44 |
func init() { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
45 |
RootCmd.AddCommand(listsCmd) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
46 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
47 |
// Subcommands |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
48 |
listsCmd.AddCommand(listsSubcommands...) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
49 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
50 |
listsCmd.PersistentFlags().UintVarP(&listsOpts.limit, "limit", "l", 0, "Limit number of API results") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
51 |
listsCmd.PersistentFlags().UintVarP(&listsOpts.keep, "keep", "k", 0, "Limit number of results") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
52 |
listsCmd.PersistentFlags().BoolVar(&listsOpts.all, "all", false, "Fetch all results") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
53 |
|
267 | 54 |
listsCmd.PersistentFlags().StringVarP(&listsOpts.listID, "list-id", "G", "", "List ID") |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
55 |
|
267 | 56 |
listsGetSubcommand.Flags().StringVarP(&listsOpts.accountID, "account-id", "a", "", "Account ID number") |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
57 |
// XXX accountUID? |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
58 |
|
267 | 59 |
listsGetAccountsSubcommand.Flags().StringVarP(&listsOpts.listID, "list-id", "G", "", "List ID") |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
60 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
61 |
listsCreateSubcommand.Flags().StringVar(&listsOpts.title, "title", "", "List title") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
62 |
listsUpdateSubcommand.Flags().StringVar(&listsOpts.title, "title", "", "List title") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
63 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
64 |
listsAddAccountsSubcommand.Flags().StringVar(&listsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs") |
267 | 65 |
listsAddAccountsSubcommand.Flags().StringVarP(&listsOpts.accountID, "account-id", "a", "", "Account ID number") |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
66 |
listsRemoveAccountsSubcommand.Flags().StringVar(&listsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs") |
267 | 67 |
listsRemoveAccountsSubcommand.Flags().StringVarP(&listsOpts.accountID, "account-id", "a", "", "Account ID number") |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
68 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
69 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
70 |
var listsSubcommands = []*cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
71 |
listsGetSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
72 |
listsCreateSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
73 |
listsUpdateSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
74 |
listsDeleteSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
75 |
listsGetAccountsSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
76 |
listsAddAccountsSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
77 |
listsRemoveAccountsSubcommand, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
78 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
79 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
80 |
var listsGetSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
81 |
Use: "show", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
82 |
Short: "Display one or several lists", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
83 |
// TODO Long: ``, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
84 |
Aliases: []string{"get", "display", "ls"}, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
85 |
RunE: listsGetRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
86 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
87 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
88 |
var listsGetAccountsSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
89 |
Use: "accounts --list-id N", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
90 |
Short: "Display a list's accounts", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
91 |
RunE: listsGetAccountsRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
92 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
93 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
94 |
var listsCreateSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
95 |
Use: "create --title TITLE", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
96 |
Short: "Create a list", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
97 |
RunE: listsSetDeleteRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
98 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
99 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
100 |
var listsUpdateSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
101 |
Use: "update --list-id N --title TITLE", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
102 |
Short: "Update a list", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
103 |
RunE: listsSetDeleteRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
104 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
105 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
106 |
var listsDeleteSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
107 |
Use: "delete --list-id N", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
108 |
Short: "Delete a list", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
109 |
Aliases: []string{"rm", "del"}, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
110 |
RunE: listsSetDeleteRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
111 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
112 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
113 |
var listsAddAccountsSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
114 |
Use: "add-accounts --list-id N --account-ids ACC1,ACC2...", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
115 |
Short: "Add one or several accounts to a list", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
116 |
Aliases: []string{"add-account"}, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
117 |
RunE: listsAddRemoveAccountsRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
118 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
119 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
120 |
var listsRemoveAccountsSubcommand = &cobra.Command{ |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
121 |
Use: "remove-accounts --list-id N --account-ids ACC1,ACC2...", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
122 |
Short: "Remove one or several accounts from a list", |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
123 |
Aliases: []string{"remove-account"}, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
124 |
RunE: listsAddRemoveAccountsRunE, |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
125 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
126 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
127 |
func listsGetRunE(cmd *cobra.Command, args []string) error { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
128 |
opt := listsOpts |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
129 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
130 |
// Log in |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
131 |
if err := madonInit(true); err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
132 |
return err |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
133 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
134 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
135 |
// Set up LimitParams |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
136 |
var limOpts *madon.LimitParams |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
137 |
if opt.all || opt.limit > 0 { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
138 |
limOpts = new(madon.LimitParams) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
139 |
limOpts.All = opt.all |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
140 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
141 |
if opt.limit > 0 { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
142 |
limOpts.Limit = int(opt.limit) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
143 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
144 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
145 |
var obj interface{} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
146 |
var err error |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
147 |
|
267 | 148 |
if opt.listID != "" { |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
149 |
var list *madon.List |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
150 |
list, err = gClient.GetList(opt.listID) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
151 |
obj = list |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
152 |
} else { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
153 |
var lists []madon.List |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
154 |
lists, err = gClient.GetLists(opt.accountID, limOpts) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
155 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
156 |
if opt.keep > 0 && len(lists) > int(opt.keep) { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
157 |
lists = lists[:opt.keep] |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
158 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
159 |
obj = lists |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
160 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
161 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
162 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
163 |
errPrint("Error: %s", err.Error()) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
164 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
165 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
166 |
if obj == nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
167 |
return nil |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
168 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
169 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
170 |
p, err := getPrinter() |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
171 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
172 |
errPrint("Error: %v", err) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
173 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
174 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
175 |
return p.printObj(obj) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
176 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
177 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
178 |
func listsGetAccountsRunE(cmd *cobra.Command, args []string) error { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
179 |
opt := listsOpts |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
180 |
|
267 | 181 |
if opt.listID == "" { |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
182 |
return errors.New("missing list ID") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
183 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
184 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
185 |
// Log in |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
186 |
if err := madonInit(true); err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
187 |
return err |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
188 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
189 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
190 |
// Set up LimitParams |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
191 |
var limOpts *madon.LimitParams |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
192 |
if opt.all || opt.limit > 0 { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
193 |
limOpts = new(madon.LimitParams) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
194 |
limOpts.All = opt.all |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
195 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
196 |
if opt.limit > 0 { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
197 |
limOpts.Limit = int(opt.limit) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
198 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
199 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
200 |
var obj interface{} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
201 |
var err error |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
202 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
203 |
var accounts []madon.Account |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
204 |
accounts, err = gClient.GetListAccounts(opt.listID, limOpts) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
205 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
206 |
if opt.keep > 0 && len(accounts) > int(opt.keep) { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
207 |
accounts = accounts[:opt.keep] |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
208 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
209 |
obj = accounts |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
210 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
211 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
212 |
errPrint("Error: %s", err.Error()) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
213 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
214 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
215 |
if obj == nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
216 |
return nil |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
217 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
218 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
219 |
p, err := getPrinter() |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
220 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
221 |
errPrint("Error: %v", err) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
222 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
223 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
224 |
return p.printObj(obj) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
225 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
226 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
227 |
func listsSetDeleteRunE(cmd *cobra.Command, args []string) error { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
228 |
const ( |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
229 |
actionUnknown = iota |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
230 |
actionCreate |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
231 |
actionUpdate |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
232 |
actionDelete |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
233 |
) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
234 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
235 |
var action int |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
236 |
opt := listsOpts |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
237 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
238 |
switch cmd.Name() { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
239 |
case "create": |
267 | 240 |
if opt.listID != "" { |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
241 |
return errors.New("list ID should not be provided with create") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
242 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
243 |
action = actionCreate |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
244 |
case "update": |
267 | 245 |
if opt.listID == "" { |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
246 |
return errors.New("list ID is required") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
247 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
248 |
action = actionUpdate |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
249 |
case "delete", "rm", "del": |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
250 |
action = actionDelete |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
251 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
252 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
253 |
// Additionnal checks |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
254 |
if action == actionUnknown { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
255 |
// Shouldn't happen. If it does, might be an unrecognized alias. |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
256 |
return errors.New("listsSetDeleteRunE: internal error") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
257 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
258 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
259 |
if action != actionDelete && opt.title == "" { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
260 |
return errors.New("the list title is required") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
261 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
262 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
263 |
// Log in |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
264 |
if err := madonInit(true); err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
265 |
return err |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
266 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
267 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
268 |
var obj interface{} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
269 |
var err error |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
270 |
var list *madon.List |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
271 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
272 |
switch action { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
273 |
case actionCreate: |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
274 |
list, err = gClient.CreateList(opt.title) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
275 |
obj = list |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
276 |
case actionUpdate: |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
277 |
list, err = gClient.UpdateList(opt.listID, opt.title) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
278 |
obj = list |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
279 |
case actionDelete: |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
280 |
err = gClient.DeleteList(opt.listID) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
281 |
obj = nil |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
282 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
283 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
284 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
285 |
errPrint("Error: %s", err.Error()) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
286 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
287 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
288 |
if obj == nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
289 |
return nil |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
290 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
291 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
292 |
p, err := getPrinter() |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
293 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
294 |
errPrint("Error: %v", err) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
295 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
296 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
297 |
return p.printObj(obj) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
298 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
299 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
300 |
func listsAddRemoveAccountsRunE(cmd *cobra.Command, args []string) error { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
301 |
opt := listsOpts |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
302 |
|
267 | 303 |
if opt.listID == "" { |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
304 |
return errors.New("missing list ID") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
305 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
306 |
|
267 | 307 |
var ids []madon.ActivityID |
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
308 |
var err error |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
309 |
ids, err = splitIDs(opt.accountIDs) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
310 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
311 |
return errors.New("cannot parse account IDs") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
312 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
313 |
|
267 | 314 |
if opt.accountID != "" { // Allow --account-id |
315 |
ids = []madon.ActivityID{opt.accountID} |
|
188
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
316 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
317 |
if len(ids) < 1 { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
318 |
return errors.New("missing account IDs") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
319 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
320 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
321 |
// Log in |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
322 |
if err := madonInit(true); err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
323 |
return err |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
324 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
325 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
326 |
switch cmd.Name() { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
327 |
case "add-account", "add-accounts": |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
328 |
err = gClient.AddListAccounts(opt.listID, ids) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
329 |
case "remove-account", "remove-accounts": |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
330 |
err = gClient.RemoveListAccounts(opt.listID, ids) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
331 |
default: |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
332 |
// Shouldn't happen. If it does, might be an unrecognized alias. |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
333 |
return errors.New("listsAddRemoveAccountsRunE: internal error") |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
334 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
335 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
336 |
if err != nil { |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
337 |
errPrint("Error: %s", err.Error()) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
338 |
os.Exit(1) |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
339 |
} |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
340 |
|
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
341 |
return nil |
a4df685950ed
Add madonctl 'lists' command
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
342 |
} |