33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { filepaths } from '../../helpers/filepaths' ;
7- import { keyValue } from '../../helpers/keyvalue' ;
6+ /* eslint-disable local/code-no-unexternalized-strings */
7+
8+ import { filepaths } from '../helpers/filepaths' ;
9+ import { keyValue } from '../helpers/keyvalue' ;
810
911const filterMessages = ( out : string ) : string => {
1012 return out . startsWith ( "warning:" ) || out . startsWith ( "error:" )
@@ -35,6 +37,7 @@ const postProcessRemoteBranches: Fig.Generator["postProcess"] = (out) => {
3537 name : elm . replace ( "*" , "" ) . trim ( ) ,
3638 description : "Current branch" ,
3739 priority : 100 ,
40+ // allow-any-unicode-next-line
3841 icon : "⭐️" ,
3942 } ;
4043 } else if ( parts [ 0 ] === "+" ) {
@@ -62,6 +65,7 @@ const listRepoMapFunction = (repo: RepoDataType) => ({
6265 name : repo . nameWithOwner ,
6366 description : repo . description ?? undefined ,
6467 //be able to see if the repo is private at a glance
68+ // allow-any-unicode-next-line
6569 icon : repo . isPrivate ? "🔒" : "👀" ,
6670} ) ;
6771
@@ -74,7 +78,9 @@ const ghGenerators: Record<string, Fig.Generator> = {
7478 const last = tokens . pop ( ) ;
7579
7680 //gatekeeper
77- if ( ! last ) return [ ] ;
81+ if ( ! last ) {
82+ return [ ] ;
83+ }
7884
7985 /**
8086 * this turns this input:
@@ -86,13 +92,17 @@ const ghGenerators: Record<string, Fig.Generator> = {
8692 const userRepoSplit = last . split ( "/" ) ;
8793
8894 // make sure it has some length.
89- if ( userRepoSplit . length === 0 ) return [ ] ;
95+ if ( userRepoSplit . length === 0 ) {
96+ return [ ] ;
97+ }
9098
9199 //get first element of arr
92100 const userOrOrg = userRepoSplit . shift ( ) ;
93101
94102 // make sure it has some existence.
95- if ( ! userOrOrg ) return [ ] ;
103+ if ( ! userOrOrg ) {
104+ return [ ] ;
105+ }
96106
97107 //run `gh repo list` cmd
98108 const { stdout, status } = await execute ( {
@@ -109,7 +119,9 @@ const ghGenerators: Record<string, Fig.Generator> = {
109119 } ) ;
110120
111121 // make sure it has some existence.
112- if ( status !== 0 ) return [ ] ;
122+ if ( status !== 0 ) {
123+ return [ ] ;
124+ }
113125
114126 //parse the JSON string output of the command
115127 const repoArr : RepoDataType [ ] = JSON . parse ( stdout ) ;
@@ -177,6 +189,7 @@ const ghGenerators: Record<string, Fig.Generator> = {
177189 name : number . toString ( ) ,
178190 displayName : title ,
179191 description : `#${ number } | ${ headRefName } ` ,
192+ // allow-any-unicode-next-line
180193 icon : state === "OPEN" ? "✅" : "☑️" ,
181194 } ;
182195 } ) ;
@@ -325,27 +338,124 @@ const completionSpec: Fig.Spec = {
325338 ] ,
326339 } ,
327340 ] ,
341+ } , {
342+ name : "api" ,
343+ description : "Make an authenticated GitHub API request" ,
344+ args : {
345+ name : "<endpoint> [flags]a" ,
346+ } ,
347+ options : [
348+ {
349+ name : "--cache" ,
350+ description : 'Cache the response, e.g. "3600s", "60m", "1h"' ,
351+ args : { name : "duration" } ,
352+ } ,
353+ {
354+ name : [ "-F" , "--field" ] ,
355+ description : "Add a typed parameter in key=value format" ,
356+ args : { name : "key:value" } ,
357+ } ,
358+ {
359+ name : "--hostname" ,
360+ description :
361+ 'The GitHub hostname for the request (default "github.com")' ,
362+ args : {
363+ name : "string" ,
364+ } ,
365+ } ,
366+ {
367+ name : [ "-i" , "--include" ] ,
368+ description :
369+ "Include HTTP response status line and headers in the output" ,
370+ } ,
371+ {
372+ name : "--input" ,
373+ description :
374+ 'The file to use as body for the HTTP request (use "-" to read from standard input)' ,
375+ args : { name : "file" } ,
376+ } ,
377+ {
378+ name : [ "-q" , "--jq" ] ,
379+ description :
380+ "Query to select values from the response using jq syntax" ,
381+ args : { name : "string" } ,
382+ } ,
383+ {
384+ name : [ "-X" , "--method" ] ,
385+ description : "The HTTP method for the request" ,
386+ args : { name : "string" , description : '(default "GET")' } ,
387+ } ,
388+ {
389+ name : "--paginate" ,
390+ description :
391+ "Make additional HTTP requests to fetch all pages of results" ,
392+ } ,
393+ {
394+ name : [ "-p" , "--preview" ] ,
395+ description :
396+ 'GitHub API preview names to request (without the "-preview" suffix)' ,
397+ args : { name : "names" } ,
398+ } ,
399+ {
400+ name : [ "-f" , "--raw-field" ] ,
401+ description : "Add a string parameter in key=value format" ,
402+ args : { name : "key=value" } ,
403+ } ,
404+ {
405+ name : "--silent" ,
406+ description : "Do not print the response body" ,
407+ } ,
408+ {
409+ name : "--slurp" ,
410+ description :
411+ 'Use with "--paginate" to return an array of all pages of either JSON arrays or objects' ,
412+ } ,
413+ {
414+ name : [ "-t" , "--template" ] ,
415+ description :
416+ 'Format JSON output using a Go template; see "gh help formatting"' ,
417+ args : { name : "string" } ,
418+ } ,
419+ {
420+ name : "--verbose" ,
421+ description : "Include full HTTP request and response in the output" ,
422+ } ,
423+ ] ,
328424 } ,
329- { name : "api" , description : "Make an authenticated GitHub API request" } ,
330425 {
331426 name : "auth" ,
332- description : "Login, logout, and refresh your authentication " ,
427+ description : "Authenticate gh and git with GitHub " ,
333428
334429 subcommands : [
335430 {
336431 name : "login" ,
337- description : "Authenticate with a GitHub host " ,
432+ description : "Gh auth login [flags] " ,
338433 options : [
434+ {
435+ name : [ "-p" , "--git-protocol" ] ,
436+ description :
437+ "The protocol to use for git operations on this host: {ssh|https}" ,
438+ args : { name : "string" } ,
439+ } ,
339440 {
340441 name : [ "-h" , "--hostname" ] ,
341442 description :
342443 "The hostname of the GitHub instance to authenticate with" ,
343- args : { name : "hostname" } ,
444+ args : { name : "string" } ,
445+ } ,
446+ {
447+ name : "--insecure-storage" ,
448+ description :
449+ "Save authentication credentials in plain text instead of credential store" ,
344450 } ,
345451 {
346452 name : [ "-s" , "--scopes" ] ,
347- description : "Additional authentication scopes for gh to have" ,
348- args : { name : "scopes" } ,
453+ description : "Additional authentication scopes to request" ,
454+ args : { name : "strings" } ,
455+ } ,
456+ {
457+ name : "--skip-ssh-key" ,
458+ description : "Skip generate/upload SSH key prompt" ,
349459 } ,
350460 {
351461 name : [ "-w" , "--web" ] ,
@@ -354,65 +464,123 @@ const completionSpec: Fig.Spec = {
354464 {
355465 name : "--with-token" ,
356466 description : "Read token from standard input" ,
357- args : { name : "token" } ,
358467 } ,
359468 ] ,
360469 } ,
361470 {
362471 name : "logout" ,
363- description : "Log out of a GitHub host " ,
472+ description : "Gh auth logout [flags] " ,
364473 options : [
365474 {
366475 name : [ "-h" , "--hostname" ] ,
367- description :
368- "The hostname of the GitHub instance to authenticate with" ,
369- args : { name : "hostname" } ,
476+ description : "The hostname of the GitHub instance to log out of" ,
477+ args : { name : "string" } ,
478+ } ,
479+ {
480+ name : [ "-u" , "--user" ] ,
481+ description : "The account to log out of" ,
482+ args : { name : "string" } ,
370483 } ,
371484 ] ,
372485 } ,
373486 {
374487 name : "refresh" ,
375- description : "Refresh stored authentication credentials " ,
488+ description : "Gh auth refresh [flags] " ,
376489 options : [
377490 {
378491 name : [ "-h" , "--hostname" ] ,
492+ description : "The GitHub host to use for authentication" ,
493+ args : { name : "string" } ,
494+ } ,
495+ {
496+ name : "--insecure-storage" ,
379497 description :
380- "The hostname of the GitHub instance to authenticate with" ,
381- args : { name : "hostname" } ,
498+ "Save authentication credentials in plain text instead of credential store" ,
499+ } ,
500+ {
501+ name : [ "-r" , "--remove-scopes" ] ,
502+ description : "Authentication scopes to remove from gh" ,
503+ args : { name : "strings" } ,
504+ } ,
505+ {
506+ name : "--reset-scopes" ,
507+ description :
508+ "Reset authentication scopes to the default minimum set of scopes" ,
382509 } ,
383510 {
384511 name : [ "-s" , "--scopes" ] ,
385512 description : "Additional authentication scopes for gh to have" ,
386- args : { name : "scopes " } ,
513+ args : { name : "strings " } ,
387514 } ,
388515 ] ,
389516 } ,
390517 {
391518 name : "setup-git" ,
392- description : "Configure git to use GitHub CLI as a credential helper " ,
519+ description : "Gh auth setup- git [flags] " ,
393520 options : [
394521 {
395- name : [ "-h " , "--hostname " ] ,
522+ name : [ "-f " , "--force " ] ,
396523 description :
397- "The hostname of the GitHub instance to authenticate with" ,
398- args : { name : "hostname" } ,
524+ "Force setup even if the host is not known. Must be used in conjunction with --hostname" ,
525+ args : { name : "--hostname" } ,
526+ } ,
527+ {
528+ name : [ "-h" , "--hostname" ] ,
529+ description : "The hostname to configure git for" ,
530+ args : { name : "string" } ,
399531 } ,
400532 ] ,
401533 } ,
402534 {
403535 name : "status" ,
404536 description : "View authentication status" ,
537+ options : [
538+ {
539+ name : [ "-a" , "--active" ] ,
540+ description : "Display the active account only" ,
541+ } ,
542+ {
543+ name : [ "-h" , "--hostname" ] ,
544+ description : "Check only a specific hostname's auth status" ,
545+ args : { name : "string" } ,
546+ } ,
547+ {
548+ name : [ "-t" , "--show-token" ] ,
549+ description : "Display the auth token" ,
550+ } ,
551+ ] ,
552+ } ,
553+ {
554+ name : "switch" ,
555+ description : "Switch the active account for a GitHub host" ,
405556 options : [
406557 {
407558 name : [ "-h" , "--hostname" ] ,
408559 description :
409- "The hostname of the GitHub instance to authenticate with " ,
410- args : { name : "hostname " } ,
560+ "The hostname of the GitHub instance to switch account for " ,
561+ args : { name : "string " } ,
411562 } ,
412563 {
413- name : "--with-token" ,
414- description : "Read token from standard input" ,
415- args : { name : "token" } ,
564+ name : [ "-u" , "--user" ] ,
565+ description : "The account to switch to" ,
566+ args : { name : "string" } ,
567+ } ,
568+ ] ,
569+ } ,
570+ {
571+ name : "token" ,
572+ description : "Gh auth token [flags]" ,
573+ options : [
574+ {
575+ name : [ "-h" , "--hostname" ] ,
576+ description :
577+ "The hostname of the GitHub instance authenticated with" ,
578+ args : { name : "string" } ,
579+ } ,
580+ {
581+ name : [ "-u" , "--user" ] ,
582+ description : "The account to output the token for" ,
583+ args : { name : "string" } ,
416584 } ,
417585 ] ,
418586 } ,
0 commit comments