Skip to content

Commit 9600fc2

Browse files
Updates all state-changing commands to be silent by default (with -PassThru) (#276)
All state-changing commands (with the exception of `New-*`) are now silent by default. Users can pass-in `-PassThru` to make them return the result that used to be returned by default. Users can revert back to the previous behavior by leveraging the new configuration value: `DefaultPassThru`. Resolves #217
1 parent 3e79c25 commit 9600fc2

33 files changed

+487
-140
lines changed

GitHubAssignees.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ function Add-GitHubAssignee
257257
NOTE: Only users with push access can add assignees to an issue.
258258
Assignees are silently ignored otherwise.
259259
260+
.PARAMETER PassThru
261+
Returns the updated GitHub Issue. By default, this cmdlet does not generate any output.
262+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
263+
of this switch.
264+
260265
.PARAMETER AccessToken
261266
If provided, this will be used as the AccessToken for authentication with the
262267
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -346,6 +351,8 @@ function Add-GitHubAssignee
346351
[Alias('UserName')]
347352
[string[]] $Assignee,
348353

354+
[switch] $PassThru,
355+
349356
[string] $AccessToken
350357
)
351358

@@ -397,7 +404,11 @@ function Add-GitHubAssignee
397404
return
398405
}
399406

400-
return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties)
407+
$result = (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties)
408+
if (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
409+
{
410+
return $result
411+
}
401412
}
402413
}
403414

GitHubConfiguration.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ function Set-GitHubConfiguration
7979
The owner name that should be used with a command that takes OwnerName as a parameter
8080
when no value has been supplied.
8181
82+
.PARAMETER DefaultPassThru
83+
Sets what the default PassThru behavior should be for commands that have a PassThru
84+
switch. By default, those commands will not return the result of the command unless
85+
the user passes in -PassThru. By setting this value to $true, those commands will
86+
always behave as if -PassThru had been specified, unless you explicitly specify
87+
-PassThru:$false on an individual command.
88+
8289
.PARAMETER DefaultRepositoryName
8390
The owner name that should be used with a command that takes RepositoryName as a parameter
8491
when no value has been supplied.
@@ -196,6 +203,8 @@ function Set-GitHubConfiguration
196203

197204
[string] $DefaultOwnerName,
198205

206+
[string] $DefaultPassThru,
207+
199208
[string] $DefaultRepositoryName,
200209

201210
[switch] $DisableLogging,
@@ -299,6 +308,7 @@ function Get-GitHubConfiguration
299308
'ApiHostName',
300309
'ApplicationInsightsKey',
301310
'DefaultOwnerName',
311+
'DefaultPassThru',
302312
'DefaultRepositoryName',
303313
'DisableLogging',
304314
'DisablePiiProtection',
@@ -656,6 +666,7 @@ function Import-GitHubConfiguration
656666
'disableTelemetry' = $false
657667
'disableUpdateCheck' = $false
658668
'defaultOwnerName' = [String]::Empty
669+
'defaultPassThru' = $false
659670
'defaultRepositoryName' = [String]::Empty
660671
'logPath' = $logPath
661672
'logProcessId' = $false
@@ -835,6 +846,10 @@ function Resolve-ParameterWithDefaultConfigurationValue
835846
if ($BoundParameters.ContainsKey($Name))
836847
{
837848
$value = $BoundParameters[$Name]
849+
if ($value -is [switch])
850+
{
851+
$value = $value.IsPresent
852+
}
838853
}
839854
else
840855
{

GitHubContents.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ filter Set-GitHubContent
255255
The email of the author of the commit. Defaults to the email of the authenticated user if
256256
not specified. If specified, AuthorName must also be specified.
257257
258+
.PARAMETER PassThru
259+
Returns the updated GitHub Content. By default, this cmdlet does not generate any output.
260+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
261+
of this switch.
262+
258263
.PARAMETER AccessToken
259264
If provided, this will be used as the AccessToken for authentication with the
260265
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -335,6 +340,8 @@ filter Set-GitHubContent
335340

336341
[string] $AuthorEmail,
337342

343+
[switch] $PassThru,
344+
338345
[string] $AccessToken
339346
)
340347

@@ -425,7 +432,11 @@ filter Set-GitHubContent
425432

426433
try
427434
{
428-
return (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties)
435+
$result = (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties)
436+
if (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
437+
{
438+
return $result
439+
}
429440
}
430441
catch
431442
{
@@ -486,7 +497,11 @@ filter Set-GitHubContent
486497
'of that file. Retrieving the SHA now.'
487498
Write-Log -Level Verbose -Message $message
488499

489-
return (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties)
500+
$result = (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties)
501+
if (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
502+
{
503+
return $result
504+
}
490505
}
491506
}
492507
}

GitHubGistComments.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ filter Set-GitHubGistComment
315315
.PARAMETER Body
316316
The new text of the comment that you wish to leave on the gist.
317317
318+
.PARAMETER PassThru
319+
Returns the updated Comment. By default, this cmdlet does not generate any output.
320+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
321+
of this switch.
322+
318323
.PARAMETER AccessToken
319324
If provided, this will be used as the AccessToken for authentication with the
320325
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -330,7 +335,7 @@ filter Set-GitHubGistComment
330335
GitHub.GistComment
331336
332337
.EXAMPLE
333-
New-GitHubGistComment -Gist 6cad326836d38bd3a7ae -Comment 1232456 -Body 'Hello World'
338+
Set-GitHubGistComment -Gist 6cad326836d38bd3a7ae -Comment 1232456 -Body 'Hello World'
334339
335340
Updates the body of the comment with ID 1232456 octocat's "hello_world.rb" gist to be
336341
"Hello World".
@@ -339,6 +344,7 @@ filter Set-GitHubGistComment
339344
SupportsShouldProcess,
340345
PositionalBinding = $false)]
341346
[OutputType({$script:GitHubGistCommentTypeName})]
347+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="PassThru is accessed indirectly via Resolve-ParameterWithDefaultConfigurationValue")]
342348
param(
343349
[Parameter(
344350
Mandatory,
@@ -362,6 +368,8 @@ filter Set-GitHubGistComment
362368
[ValidateNotNullOrEmpty()]
363369
[string] $Body,
364370

371+
[switch] $PassThru,
372+
365373
[string] $AccessToken
366374
)
367375

@@ -387,7 +395,11 @@ filter Set-GitHubGistComment
387395
'TelemetryProperties' = $telemetryProperties
388396
}
389397

390-
return (Invoke-GHRestMethod @params | Add-GitHubGistCommentAdditionalProperties)
398+
$result = (Invoke-GHRestMethod @params | Add-GitHubGistCommentAdditionalProperties)
399+
if (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
400+
{
401+
return $result
402+
}
391403
}
392404

393405
filter Add-GitHubGistCommentAdditionalProperties

GitHubGists.ps1

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ filter Copy-GitHubGist
519519
.PARAMETER Gist
520520
The ID of the specific gist that you wish to fork.
521521
522+
.PARAMETER PassThru
523+
Returns the newly created gist fork. By default, this cmdlet does not generate any output.
524+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
525+
of this switch.
526+
522527
.PARAMETER AccessToken
523528
If provided, this will be used as the AccessToken for authentication with the
524529
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -539,16 +544,18 @@ filter Copy-GitHubGist
539544
Forks octocat's "hello_world.rb" gist.
540545
541546
.EXAMPLE
542-
Fork-GitHubGist -Gist 6cad326836d38bd3a7ae
547+
$result = Fork-GitHubGist -Gist 6cad326836d38bd3a7ae -PassThru
543548
544549
Forks octocat's "hello_world.rb" gist. This is using the alias for the command.
545550
The result is the same whether you use Copy-GitHubGist or Fork-GitHubGist.
551+
Specifying the -PassThru switch enables you to get a reference to the newly created fork.
546552
#>
547553
[CmdletBinding(
548554
SupportsShouldProcess,
549555
PositionalBinding = $false)]
550556
[OutputType({$script:GitHubGistSummaryTypeName})]
551557
[Alias('Fork-GitHubGist')]
558+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="PassThru is accessed indirectly via Resolve-ParameterWithDefaultConfigurationValue")]
552559
param(
553560
[Parameter(
554561
Mandatory,
@@ -558,6 +565,8 @@ filter Copy-GitHubGist
558565
[ValidateNotNullOrEmpty()]
559566
[string] $Gist,
560567

568+
[switch] $PassThru,
569+
561570
[string] $AccessToken
562571
)
563572

@@ -578,8 +587,13 @@ filter Copy-GitHubGist
578587
'TelemetryProperties' = $telemetryProperties
579588
}
580589

581-
return (Invoke-GHRestMethod @params |
590+
$result = (Invoke-GHRestMethod @params |
582591
Add-GitHubGistAdditionalProperties -TypeName $script:GitHubGistSummaryTypeName)
592+
593+
if (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
594+
{
595+
return $result
596+
}
583597
}
584598

585599
filter Set-GitHubGistStar
@@ -1075,6 +1089,11 @@ filter Set-GitHubGist
10751089
.PARAMETER Force
10761090
If this switch is specified, you will not be prompted for confirmation of command execution.
10771091
1092+
.PARAMETER PassThru
1093+
Returns the updated gist. By default, this cmdlet does not generate any output.
1094+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
1095+
of this switch.
1096+
10781097
.PARAMETER AccessToken
10791098
If provided, this will be used as the AccessToken for authentication with the
10801099
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -1119,6 +1138,7 @@ filter Set-GitHubGist
11191138
DefaultParameterSetName='Content',
11201139
PositionalBinding = $false)]
11211140
[OutputType({$script:GitHubGistTypeName})]
1141+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="PassThru is accessed indirectly via Resolve-ParameterWithDefaultConfigurationValue")]
11221142
param(
11231143
[Parameter(
11241144
Mandatory,
@@ -1136,6 +1156,8 @@ filter Set-GitHubGist
11361156

11371157
[switch] $Force,
11381158

1159+
[switch] $PassThru,
1160+
11391161
[string] $AccessToken
11401162
)
11411163

@@ -1231,8 +1253,13 @@ filter Set-GitHubGist
12311253

12321254
try
12331255
{
1234-
return (Invoke-GHRestMethod @params |
1256+
$result = (Invoke-GHRestMethod @params |
12351257
Add-GitHubGistAdditionalProperties -TypeName $script:GitHubGistTypeName)
1258+
1259+
if (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
1260+
{
1261+
return $result
1262+
}
12361263
}
12371264
catch
12381265
{
@@ -1275,6 +1302,11 @@ function Set-GitHubGistFile
12751302
.PARAMETER Content
12761303
The content of a single file that should be part of the gist.
12771304
1305+
.PARAMETER PassThru
1306+
Returns the updated gist. By default, this cmdlet does not generate any output.
1307+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
1308+
of this switch.
1309+
12781310
.PARAMETER AccessToken
12791311
If provided, this will be used as the AccessToken for authentication with the
12801312
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -1314,6 +1346,7 @@ function Set-GitHubGistFile
13141346
[OutputType({$script:GitHubGistTypeName})]
13151347
[Alias('Add-GitHubGistFile')]
13161348
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="This is a helper method for Set-GitHubGist which will handle ShouldProcess.")]
1349+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="PassThru is accessed indirectly via Resolve-ParameterWithDefaultConfigurationValue")]
13171350
param(
13181351
[Parameter(
13191352
Mandatory,
@@ -1345,6 +1378,8 @@ function Set-GitHubGistFile
13451378
[ValidateNotNullOrEmpty()]
13461379
[string] $Content,
13471380

1381+
[switch] $PassThru,
1382+
13481383
[string] $AccessToken
13491384
)
13501385

@@ -1383,6 +1418,7 @@ function Set-GitHubGistFile
13831418
$params = @{
13841419
'Gist' = $Gist
13851420
'Update' = $files
1421+
'PassThru' = (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
13861422
'AccessToken' = $AccessToken
13871423
}
13881424

@@ -1412,6 +1448,11 @@ function Remove-GitHubGistFile
14121448
.PARAMETER Force
14131449
If this switch is specified, you will not be prompted for confirmation of command execution.
14141450
1451+
.PARAMETER PassThru
1452+
Returns the updated gist. By default, this cmdlet does not generate any output.
1453+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
1454+
of this switch.
1455+
14151456
.PARAMETER AccessToken
14161457
If provided, this will be used as the AccessToken for authentication with the
14171458
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -1447,6 +1488,7 @@ function Remove-GitHubGistFile
14471488
[OutputType({$script:GitHubGistTypeName})]
14481489
[Alias('Delete-GitHubGistFile')]
14491490
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="This is a helper method for Set-GitHubGist which will handle ShouldProcess.")]
1491+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="PassThru is accessed indirectly via Resolve-ParameterWithDefaultConfigurationValue")]
14501492
param(
14511493
[Parameter(
14521494
Mandatory,
@@ -1465,6 +1507,8 @@ function Remove-GitHubGistFile
14651507

14661508
[switch] $Force,
14671509

1510+
[switch] $PassThru,
1511+
14681512
[string] $AccessToken
14691513
)
14701514

@@ -1491,6 +1535,7 @@ function Remove-GitHubGistFile
14911535
'Delete' = $files
14921536
'Force' = $Force
14931537
'Confirm' = ($Confirm -eq $true)
1538+
'PassThru' = (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
14941539
'AccessToken' = $AccessToken
14951540
}
14961541

@@ -1520,6 +1565,11 @@ filter Rename-GitHubGistFile
15201565
.PARAMETER NewName
15211566
The new name of the file for the gist.
15221567
1568+
.PARAMETER PassThru
1569+
Returns the updated gist. By default, this cmdlet does not generate any output.
1570+
You can use "Set-GitHubConfiguration -DefaultPassThru" to control the default behavior
1571+
of this switch.
1572+
15231573
.PARAMETER AccessToken
15241574
If provided, this will be used as the AccessToken for authentication with the
15251575
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
@@ -1544,6 +1594,7 @@ filter Rename-GitHubGistFile
15441594
PositionalBinding = $false)]
15451595
[OutputType({$script:GitHubGistTypeName})]
15461596
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="This is a helper method for Set-GitHubGist which will handle ShouldProcess.")]
1597+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="PassThru is accessed indirectly via Resolve-ParameterWithDefaultConfigurationValue")]
15471598
param(
15481599
[Parameter(
15491600
Mandatory,
@@ -1565,6 +1616,8 @@ filter Rename-GitHubGistFile
15651616
[ValidateNotNullOrEmpty()]
15661617
[string] $NewName,
15671618

1619+
[switch] $PassThru,
1620+
15681621
[string] $AccessToken
15691622
)
15701623

@@ -1574,6 +1627,7 @@ filter Rename-GitHubGistFile
15741627
$params = @{
15751628
'Gist' = $Gist
15761629
'Update' = @{$FileName = @{ 'fileName' = $NewName }}
1630+
'PassThru' = (Resolve-ParameterWithDefaultConfigurationValue -Name PassThru -ConfigValueName DefaultPassThru)
15771631
'AccessToken' = $AccessToken
15781632
}
15791633

0 commit comments

Comments
 (0)