Github cli release12/6/2023 For example, to get the current user's name: gh api user -jq '.name'įor more information, see gh help formatting. For example, to fetch information about the current user: gh api userĪll commands that output JSON data also have options to filter that data into something more immediately usable by scripts. If there is not a core command to fetch specific data from GitHub, you can use the gh api command to access the GitHub API. For example, to return a JSON object listing the number, title, and mergeability status of pull requests: gh pr list -json number,title,mergeStateStatus Many core commands support the -json flag for fetching data programatically. To avoid prompting, supply the necessary information explicitly via arguments.įor example, to create an issue programmatically, specify the title and body: gh issue create -title "My Title" -body "Issue description" When scripting with those commands, a prompt is often undesirable. Some GitHub CLI core commands will prompt the user for input. Then echo "Hi $name_arg" else echo "Hello and welcome, $name_arg" fi Calling core commands in non-interactive mode Then echo "You haven't told us your name." elif When the script is called with the -verbose flag, the script prints a different greeting. When the script is called with the -name flag, the script sets the next value after the flag to name_arg. When the script is called with the -h or -help flag, the script prints help text instead of continuing execution. You can use arguments to take user input or to modify the behavior of the script.įor example, this script handles multiple flags. In a bash script, you can reference arguments with $1, $2, etc. Tips for writing interpreted GitHub CLI extensions Handling arguments and flagsĪll command line arguments following a gh my-extension-name command will be passed to the extension script. For more information about how to add a repository topic, see " Classifying your repository with topics." This will make the extension appear on the gh-extension topic page. Optionally, to help other users discover your extension, add the repository topic gh-extension. Gh repo create gh-EXTENSION-NAME -source=. Replace EXTENSION-NAME with the name of your extension. gh EXTENSION-NAMEįrom your directory, create a repository to publish your extension. For example: #!/usr/bin/env bash set -eĮxec gh api user -jq '"You are (\(.name))."'įrom your directory, install the extension as a local extension. Write your script in the executable file. On Windows, you can run git init -b main, git add file_name, then git update-index -chmod=+x file_name. On Unix, you can execute chmod +x file_name in the command line to make file_name executable. Note: Make sure that your file is executable. In the directory that you created, add an executable file with the same name as the directory. gh extension create -precompiled=other EXTENSION-NAMEĪdd some initial code for your extension in your compiled language of choice.įill in script/build.sh with code to build your extension to ensure that your extension can be built automatically.Ĭreating an interpreted extension manuallyĬreate a local directory called gh-EXTENSION-NAME for your extension. Replace EXTENSION-NAME with the name of your extension and specify -precompiled=other. Set up a new extension by using the gh extension create subcommand. You can use the -precompiled=other argument to create a project for your non-Go precompiled extension, including workflow scaffolding. gh extension create -precompiled=go EXTENSION-NAMEĬreating a non-Go precompiled extension with gh extension create Replace EXTENSION-NAME with the name of your extension and specify -precompiled=go. You can use the -precompiled=go argument to create a Go-based project for your extension, including Go scaffolding, workflow scaffolding, and starter code. gh extension create EXTENSION-NAMEįollow the printed instructions to finalize and optionally publish your extension.Ĭreating a precompiled extension in Go with gh extension create You can use the gh extension create command to create a project for your extension, including a bash script that contains some starter code. Note: Running gh extension create with no arguments will start an interactive wizard.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |