generated from fastai/nbdev_template
-
Notifications
You must be signed in to change notification settings - Fork 57
/
cli.html
478 lines (362 loc) · 16.3 KB
/
cli.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
---
title: Command line interface
keywords: fastai
sidebar: home_sidebar
summary: "Access to the GitHub API from the command line"
description: "Access to the GitHub API from the command line"
nb_path: "10_cli.ipynb"
---
<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: 10_cli.ipynb
# command to build the docs after a change: nbdev_build_docs
-->
<div class="container" id="notebook-container">
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
</div>
{% endraw %}
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>You can use <a href="/core.html#GhApi"><code>GhApi</code></a> via the command line, and can access nearly everything in the <a href="https://docs.github.com/en/free-pro-team@latest/rest">GitHub API</a>.</p>
<p>There are three commands provided. For most people, <a href="/cli.html#ghapi"><code>ghapi</code></a> will be the easiest to use. All three commands take the following parameters:</p>
<ul>
<li><code>--help</code>: list all parameters to this command and endpoint</li>
<li><code>--headers</code>: A list of extra headers to pass, JSON-encoded</li>
<li><code>--token</code>: A GitHub authentation token</li>
<li><code>--debug</code>: Print requests before sending them</li>
</ul>
<p>If you have an environment variable <code>GITHUB_TOKEN</code> defined, then it will be used for the token if <code>--token</code> is not passed. If neither is provided, then the commands will not be able to acces any authentication functionality.</p>
<p>We'll now look at each of the three commands in turn.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="The-ghapi-command">The <a href="/cli.html#ghapi"><code>ghapi</code></a> command<a class="anchor-link" href="#The-ghapi-command"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>To get started with the <a href="/cli.html#ghapi"><code>ghapi</code></a> command, first find the name of the operation you wish to perform. If you've used the Python API, then you already know the operation names - they're whatever you type in Python after "<code>api.</code>". To find the name of the operation you need, search the <a href="https://ghapi.fast.ai/fullapi.html">full API reference</a> which contains information about every endpoint in the entire GitHub API. For instance, if you want to work with GitHub Issues, then searching for "issues" on the full reference page will take you to <a href="https://ghapi.fast.ai/fullapi.html#issues">this section</a>.</p>
<p>The first operation listed there is <a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/issues#list-issues-assigned-to-the-authenticated-user">issues.list</a>, shown with a link to the official GitHub documentation, and a list of parameters that the command accepts. You'll see the official docs list some parameters, such as "<code>accept</code>", which aren't listed in the GhApi reference - that's because GhApi automatically set some parameters for you.</p>
<p>You'll also see that the parameter list on the official docs includes a column marked "<strong>in</strong>", which can be "header", "query", "path", or "body". The <a href="/cli.html#ghapi"><code>ghapi</code></a> command handles that distinction for you, so you can ignore it for now.</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
</div>
{% endraw %}
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>To use <a href="/cli.html#ghapi"><code>ghapi</code></a>, pass the method name (exactly the same as you'd use in the Python API) as the first parameter, followed by any positional parameters required, and then keyword arguments with "<code>--</code>" before each parameter name.</p>
<p>For instance, <a href="https://ghapi.fast.ai/fullapi.html#git">git.get_ref</a> takes three parameters: <code>owner</code>, <code>repo</code>, and <code>ref</code>. If we wish to pass the first two as positional parameters, and the last as a named argument, then we'd call:</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> ghapi git.get_ref fastai ghapi-test --ref heads/master
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>- ref: refs/heads/master
- node_id: MDM6UmVmMzE1NzEyNTg4OnJlZnMvaGVhZHMvbWFzdGVy
- url: https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master
- object:
- sha: f086d17cc9ec8e99f466c613cab44f98abad1db6
- type: commit
- url: https://api.github.com/repos/fastai/ghapi-test/git/commits/f086d17cc9ec8e99f466c613cab44f98abad1db6
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>(NB: The "<code>!</code>" before the examples such as the one above is only needed when calling the commands from Jupyer Notebook. In your terminal, do not include the "<code>!</code>" prefix.)</p>
<p>If you pass just <code>--help</code> after the operation name, you'll see a full list of all parameters accepted, and a link to the official GitHub documentation.</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> ghapi git.get_ref --help
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>git.get_ref(owner, repo, ref)
https://docs.github.com/rest/reference/git#get-a-reference
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Helper methods are also supported, e.g:</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> ghapi create_release --help
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>(tag_name, branch='master', name=None, body='', draft=False, prerelease=False, files=None)
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="The-ghpath-command">The <a href="/cli.html#ghpath"><code>ghpath</code></a> command<a class="anchor-link" href="#The-ghpath-command"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>If you find the endpoint you want in the GitHub docs, rather than the GhApi reference, you'll see a <code>path</code> and a <code>verb</code> instead of an operation name. For example, here's the GitHub documentation for <a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/git#get-a-reference">git.getref</a>. The white text on blue background section shows that the verb required is "<code>GET</code>". Next to that is the path, which is listed as "<code>/repos/{owner}/{repo}/git/ref/{ref}</code>".</p>
<p>To call an endpoint when you have this information from the GitHub docs, use the <a href="/cli.html#ghpath"><code>ghpath</code></a> command. The arguments are exactly the same as <a href="/cli.html#ghapi"><code>ghapi</code></a>, except that instead of an operation name, you provide the path (which you can paste directly from the GitHub docs) and verb.</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Just like with <a href="/cli.html#ghapi"><code>ghapi</code></a>, <a href="/cli.html#ghpath"><code>ghpath</code></a> handles header, query, path and body parameters for you automatically.</p>
<p>For instance, the previous <code>git.get_ref</code> command using <a href="/cli.html#ghpath"><code>ghpath</code></a> is:</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> ghpath <span class="s1">'/repos/{owner}/{repo}/git/ref/{ref}'</span> get fastai ghapi-test --ref heads/master
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>- ref: refs/heads/master
- node_id: MDM6UmVmMzE1NzEyNTg4OnJlZnMvaGVhZHMvbWFzdGVy
- url: https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master
- object:
- sha: f086d17cc9ec8e99f466c613cab44f98abad1db6
- type: commit
- url: https://api.github.com/repos/fastai/ghapi-test/git/commits/f086d17cc9ec8e99f466c613cab44f98abad1db6
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="The-ghraw-command">The <a href="/cli.html#ghraw"><code>ghraw</code></a> command<a class="anchor-link" href="#The-ghraw-command"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Sometimes, you just want to call an exact path directly, handling the path and query parameters yourself. The <a href="/cli.html#ghraw"><code>ghraw</code></a> command provides that functionality. Like with <a href="/cli.html#ghpath"><code>ghpath</code></a>, you pass the path and verb as the first two arguments, but now you have to fill in all the path parameters yourself, plus construct the query string yourself (if one is required). If you need to pass body parameters, use the <code>--data</code> parameter, which requires that you encode the request body appropriately (which is JSON-encoded for most GitHub endpoints).</p>
<p>For instance, the <code>git.git_ref</code> example show in the previous two sections does not have any header, body, or query parameters, so we need only insert the path parameters, which results in this call:</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> ghraw /repos/fastai/ghapi-test/git/ref/heads/master get
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>- ref: refs/heads/master
- node_id: MDM6UmVmMzE1NzEyNTg4OnJlZnMvaGVhZHMvbWFzdGVy
- url: https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master
- object:
- sha: f086d17cc9ec8e99f466c613cab44f98abad1db6
- type: commit
- url: https://api.github.com/repos/fastai/ghapi-test/git/commits/f086d17cc9ec8e99f466c613cab44f98abad1db6
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Shell-completions">Shell completions<a class="anchor-link" href="#Shell-completions"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>Shell completions are provided for <a href="/cli.html#ghapi"><code>ghapi</code></a> behind the scenes by the <code>completion-ghapi</code> command (which is implemented with the <a href="/cli.html#completion_ghapi"><code>completion_ghapi</code></a> function). You probably won't need to call this yourself - it will be called for you as part by your shell.</p>
</div>
</div>
</div>
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> completion-ghapi git
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>git
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> completion-ghapi gi
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>gists git gitignore
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> completion-ghapi git.
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>git.create_blob git.create_commit git.create_ref git.create_tag git.create_tree git.delete_ref git.get_blob git.get_commit git.get_ref git.get_tag git.get_tree git.list_matching_refs git.name git.update_ref git.verbs
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
{% raw %}
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span> completion-ghapi git.g
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>git.get_blob git.get_commit git.get_ref git.get_tag git.get_tree
</pre>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Tab-completion">Tab completion<a class="anchor-link" href="#Tab-completion"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>You can enable tab completion for <a href="/cli.html#ghapi"><code>ghapi</code></a> by placing the following command at the end of your <code>~/.bashrc</code> or <code>~/.zshrc</code> file:</p>
<div class="highlight"><pre><span></span><span class="nb">eval</span> <span class="s2">"</span><span class="k">$(</span>completion-ghapi --install<span class="k">)</span><span class="s2">"</span>
</pre></div>
</div>
</div>
</div>
</div>