GetLogs 4 -OneLine
GetLogs -Since ([datetime]::Now.AddDays(-7)) -OneLine -Limit 3
GetLogs -Since ([datetime]::Now.AddDays(-7)) -OneLine
GetLogs -Since ([datetime]::Now.AddDays(-7))
Last active
August 24, 2024 22:32
-
-
Save ninmonkey/7be44ed72de3b62c33de060163865183 to your computer and use it in GitHub Desktop.
using `[List[Object]]` to build native `git` command arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace System.Collections.Generic | |
function GetLogs { | |
# BinArgs is built conditionally based on what parameters are used | |
param( | |
[int] $Limit, | |
[datetime] $Since, | |
[switch] $OneLine, | |
# preview the command line that's generated without running git | |
[switch] $WhatIf | |
) | |
[List[Object]] $binArgs = @( 'log' ) | |
if( $Limit -gt 0 ) { | |
$binArgs.AddRange(@( | |
'-n', $Limit )) | |
} | |
if( $OneLine ) { $binArgs.Add( '--pretty=oneline' ) } | |
if( $Since ) { | |
$binArgs.AddRange(@( | |
('--since={0}' -f $Since.ToString('u') ) | |
)) | |
} | |
$binArgs -join ' ' | Write-verbose -verbose | |
if( $WhatIf ) { return } | |
& git @binArgs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment