Splatting the GitHub CLI

Brevity may be the soul of wit, but I may be bad at it.
But let's try to make a quick post about a little daily PowerShell timesaver: splatting the GitHub CLI.
I'm going to show you how you can save typing and time with the GitHub CLI.
What is Splatting?
Splatting is a simple technique in PowerShell. It lets you pass multiple parameters. It's been there since PowerShell version 2. This is old, consistent technique.
Most people are used to splatting a dictionary, like:
# You can splat a dictionary
$MyId = @{id=$pid}
Get-Process @MyIdThis is a cool and useful technique, and most people overlook the other half of splatting:
# You can splat a list
$allIssues = @('--state', 'all', '--limit, '2kb')
gh issue list @allIssuesThe Trick
You just saw it.
There are millions of apps you could use this trick with.
I just happen to use the github cli on most days.
You're trading typing all of those arguments for typing a shorter string.
It saves seconds every time you use it.
And it's one simple line.
You can stick it in your profile and every time you're using PowerShell, you'll have those variables to use.
You can just type this sort of trick in if you find yourself using the same parameters.
Think of it as a preset of parameters. Because that's basically what it is.
Multiple Splats
It's important to know that you can do multiple splats.
Here's a simple example:
$bug = @('--label', 'bug')
$assignMe = @('--assignee', '@me')
gh issue create --title 'Some Issue' --body 'Some problem' @bug @assignMeThis would create a bug.
Let's make another, longer one:
# Get issue information as json.
$IssueAsJson= @('--json', (
'assignees','author','body','closed','closedAt',
'closedByPullRequestsReferences','comments','createdAt',
'isPinned','labels','milestone','number','reactionGroups',
'state','stateReason','title','updatedAt','url' -join ','
))
$allIssues = @('--state', 'all', '--limit, '2kb')
$IssueList = gh issue list @allIssues @IssueAsJson | ConvertFrom-Json
$issueListIf you run this, you
- List all of the issues from a repo as json
- Convert them from json into objects
Feel free to copy/paste these tricks into your profile. They're handy!
Hope This Helps,
James