• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

cmd/H16-Feb-2020-4,0263,228

examples/H16-Feb-2020-6947

printer/H16-Feb-2020-1,3911,063

templates/H16-Feb-2020-629580

vendor/H03-May-2022-363,579299,268

.gitignoreH A D16-Feb-202059 118

.travis.ymlH A D16-Feb-2020186 1716

LICENSEH A D16-Feb-20201.1 KiB2217

README.mdH A D16-Feb-202010.9 KiB320239

configuration.mdH A D16-Feb-20203.1 KiB7959

go.modH A D16-Feb-2020823 2522

go.sumH A D16-Feb-202021.3 KiB231230

main.goH A D16-Feb-20201.2 KiB307

README.md

1# madonctl
2
3Golang command line interface for the Mastodon API
4
5[![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/McKael/madonctl/master/LICENSE)
6[![Build Status](https://travis-ci.org/McKael/madonctl.svg?branch=master)](https://travis-ci.org/McKael/madonctl)
7
8`madonctl` is a [Go](https://golang.org/) CLI tool to use the Mastodon REST API.
9
10It is built on top of [madon](https://github.com/McKael/madon), my Golang
11implementation of the API.
12
13## Installation
14
15### Download
16
17Check the [Release page](https://github.com/McKael/madonctl/releases) for some
18pre-built binaries.
19
20More pre-built binaries might be available from the [Homepage](https://lilotux.net/~mikael/pub/madonctl/)
21(development version and builds for a few other platforms).
22
23### From source
24
25madonctl now uses Go modules introduced with Go v1.11.
26
27For backward compatibility, dependencies have been vendored and you should
28still be able to build it "the old way" with:
29
30    go get github.com/McKael/madonctl
31
32Alternatively, with Go >= 1.11:
33
34    git clone https://github.com/McKael/madonctl
35    cd madonctl
36    go build    # (or go install)
37
38and you should be able to use `madonctl`.
39
40Travis automated testing is run for Go versions 1.11 - 1.13.
41
42## Usage
43
44### Configuration
45
46In order to use madonctl, you need to specify the instance name or URL, and
47usually provide an account login/password (or a token).
48
49These settings can be passed as command line arguments or environment variables,
50but the easiest way is to use a configuration file.
51
52Note that you can **generate a configuration file** for your settings with
53
54`madonctl config dump -i mastodon.social -L username@domain -P password`
55
56(You can redirect the output to a configuration file.)
57
58If you don't want to use the password or if you have enabled *Two-factor
59authentication*, you can also use **OAuth2** with the `oauth2` command:
60
61`madonctl -i mastodon.social oauth2 > madonctl.yaml`
62
63For details on the configuration, please check the [configuration](configuration.md) page.
64
65### Usage
66
67The complete list of commands is available in the online help (`madonctl help`,
68`madonctl command --help`...) or in the
69[manpages](https://lilotux.net/~mikael/pub/madonctl/manual/html/).
70
71### Examples
72
73This is a non-exhaustive list of commands, showing how madonctl works.
74
75To post a simple "toot":
76``` sh
77% madonctl toot "Hello, World"
78```
79
80You can change the toot visibility, add a Content Warning (a.k.a. spoiler)
81or send a media file:
82``` sh
83% madonctl toot --visibility direct "@McKael Hello, you"
84% madonctl toot --visibility private --spoiler CW "The answer was 42"
85% madonctl post --file image.jpg Selfie # Send a media file
86```
87Note: The default toot visibility can be set in the configuration file with
88the `default_visibility` setting or with the environment variable (example
89`export MADONCTL_DEFAULT_VISIBILITY=unlisted`).
90
91Send (text) file content as new message:
92```
93% madonctl toot --text-file message.txt
94```
95
96... or read message from standard input:
97```
98% echo "Hello from #madonctl" | madonctl toot --stdin
99```
100
101Reply to a message:
102``` sh
103% madonctl toot --in-reply-to 1234 --visibility direct "@user1 @user2 response"
104% madonctl toot --in-reply-to 1234 --add-mentions "response"
105```
106The flag `--add-mentions` automatically adds mentions based on the toot you're
107replying to.
108
109Some **account-related commands**:
110``` sh
111% madonctl accounts blocked                       # List blocked accounts
112% madonctl accounts muted                         # List muted accounts
113
114% madonctl account notifications --list --all    # List really all notifications
115% madonctl account notifications --list --clear  # List and clear notifications
116% madonctl account notifications --notification-id 1234 # Display notification
117% madonctl account notifications --dismiss --notification-id 1234
118```
119
120Note: By default, madonctl will send a single query.  If you want all available
121results you should use the `--all` flag.  If you use a `--limit` value,
122madonctl might send several queries until the number of results reaches this
123value.
124
125**Update** your account information:
126``` sh
127% madonctl account update --display-name "John"  # Update display name
128% madonctl account update --note "Newcomer"      # Update user note (bio)
129% madonctl account update --note ""              # Clear note
130% madonctl account update --avatar me.png        # Update avatar
131
132% madonctl account update --bot               # Advertise account as automated
133% madonctl account update --default-sensitive # Set medias sensitive by default
134% madonctl account update --default-language fra    # Set default toot language
135% madonctl account update --default-privacy private # Set default toot privacy
136```
137
138See your own **posts**:
139``` sh
140% madonctl account statuses                      # See last posts
141% madonctl account statuses --all                # See all statuses
142```
143
144Display accounts you're **following** or your **followers**:
145``` sh
146% madonctl accounts following                     # See last following
147% madonctl accounts following --all               # See all followed accounts
148% madonctl accounts followers --limit 30          # Last 30 followers
149```
150
151Add/remove a **favourite**, **boost** a status...
152``` sh
153% madonctl status --status-id 416671 favourite    # Fave a status
154% madonctl status --status-id 416671 boost        # Boost (reblog) a status
155
156% madonctl status --status-id 416671 unboost       # Cancel a boost
157% madonctl status --status-id 416671 boost --unset # Cancel a boost (deprecated)
158```
159
160**Pin/unpin** a status...
161``` sh
162% madonctl status --status-id 533769 pin          # Pin a status
163% madonctl status --status-id 533769 unpin        # Unpin a status
164% madonctl status --status-id 533769 pin --unset  # Unpin a status (deprecated)
165```
166
167**Pin/unpin** an account (i.e., account endorsement)...
168``` sh
169% madonctl status --account-id 1234 pin           # Pin (endorse) an account
170% madonctl status --account-id 1234 unpin         # Unpin an account
171
172% madonctl status pin @Gargron@mastodon.social
173```
174
175Search for an account (only accounts known to your instance):
176``` sh
177% madonctl accounts search gargron
178```
179
180**Follow** an account with known ID:
181``` sh
182% madonctl account follow --account-id 1234
183```
184
185Follow a remote account:
186``` sh
187% madonctl account follow --remote Gargron@mastodon.social
188```
189
190madonctl 2.3.0+ is able to recognize the kind of argument to specify and to
191use the relevant API calls, so the previous commands could be written as:
192``` sh
193% madonctl account follow 1234
194% madonctl account follow Gargron@mastodon.social
195% madonctl account follow https://mastodon.social/@Gargron
196```
197
198Note: If you know the numeric account ID, you should use it to save extra API
199calls.
200
201**Search** for accounts, statuses or hashtags:
202``` sh
203% madonctl search gargron
204% madonctl search mastodon
205```
206
207When the account ID is unknown, --user-id can be useful.\
208You can specify the (instance-specific) account ID number (--account-id) or
209the user ID (--user-id).  In the later case, madonctl will search for the
210user so it must match exactly the ID known to your instance (without the
211@domain suffix if the user is on the same instance).  The --user-id flag can
212also contain an HTTP account URL.
213``` sh
214% madonctl account --user-id Gargron@mastodon.social -l5 statuses # Last 5 statuses
215% madonctl account --user-id https://mastodon.social/@Gargron -l5 statuses # Same
216```
217
218With madonctl 2.3.0+, you can use the shorter forms:
219``` sh
220% madonctl account statuses -l5 Gargron@mastodon.social
221% madonctl account statuses -l5 https://mastodon.social/@Gargron
222% madonctl account statuses -l5 1   # (account ID)
223```
224
225Please note that the form "Gargron@mastodon.social" will only work if this
226account is known by the instance.  If it is unknown, the https link should work
227(and the Mastodon server will learn about the account).
228
229Read **timelines**:
230``` sh
231% madonctl timeline                 # Display home timeline
232% madonctl timeline home            # (same as previous command)
233% madonctl timeline public          # Display federated timeline
234% madonctl timeline public --local  # Display public local timeline
235% madonctl timeline direct          # Display timeline of direct messages
236
237% madonctl timeline --limit 3       # Display 3 latest home timeline messages
238```
239
240Use the **streaming API** and fetch timelines and notifications:
241``` sh
242% madonctl stream                   # Stream home timeline and notifications
243% madonctl stream local             # Stream local timeline
244% madonctl stream public            # Stream federated timeline
245% madonctl stream direct            # Stream direct messages
246```
247
248You can also use **hashtag streams**:
249``` sh
250% madonctl stream :mastodon         # Stream for hastag 'mastodon'
251% madonctl stream :madonctl,golang  # Stream for several hashtags
252```
253
254Please note that madonctl will use one socket per stream, so the number of
255concurrent hashtags is currently limited to 4 for "politeness".
256
257It is also possible to send every stream event (notification or status) to
258an **external command**.  You can can even combine it with a customized theme.
259The contents will be sent to the standard input of this command:
260``` sh
261madonctl stream --command gateway.sh --theme gateway
262```
263
264(Almost) All commands have a **customizable output**:
265``` sh
266% madonctl account show            # Display an account
267% madonctl account show -o yaml    # Display an account, in yaml
268% madonctl account show -o json    # Display an account, in json
269% madonctl stream local -o json     # Stream local timeline and output to JSON
270```
271
272You can also use Go (Golang) **templates**:
273``` sh
274% madonctl account --account-id 1 followers --template '{{.acct}}{{"\n"}}'
275```
276
277You can write and use [themes](templates) as well:
278```
279madonctl --theme=ansi timeline
280```
281
282There are many more commands, you can find them in the online help or the manpage.
283
284
285### Shell completion
286
287If you want **shell completion**, you can generate scripts with the following command: \
288`madonctl completion bash` (or zsh)
289
290Then, just source the script in your shell.
291
292For example, I have this line in my .zshrc:
293
294`source <(madonctl completion zsh)`
295
296### Commands output
297
298The output can be set to **json**, **yaml** or to a **Go template** for all commands.\
299If you are familiar with Kubernetes' kubectl, it is very similar.
300
301For example, you can display your user token with:\
302`madonctl config whoami --template '{{.access_token}}'`\
303or the application ID with:\
304`madonctl config dump --template '{{.ID}}'`
305
306All the users that have favorited a given status:\
307`madonctl status --status-id 101194 favourited-by --template '{{.username}}{{"\n"}}'`
308
309Sets of templates can be grouped as **themes**.
310
311For more complex templates, one can use the `--template-file` option.\
312See the [themes & templates](templates) folder.
313
314## References
315
316- [madonctl manpages](https://lilotux.net/~mikael/pub/madonctl/manual/html/)
317- [madon](https://github.com/McKael/madon), the Go library for Mastodon API
318- [Mastodon API documentation](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md)
319- [Mastodon repository](https://github.com/tootsuite/mastodon)
320