diff --git a/Docs/Get-GitModule.md b/Docs/Get-GitModule.md index f7776f0..236c54d 100644 --- a/Docs/Get-GitModule.md +++ b/Docs/Get-GitModule.md @@ -98,7 +98,7 @@ Accept wildcard characters: False ### -Name You can query already installed modules for their online version if ProjectUri is specified in the module info. -To do this, just specify module name(s) with parameter -Names. +To do this, just specify module name(s) with parameter -Name. ```yaml Type: String[] diff --git a/Docs/Update-GitModule.md b/Docs/Update-GitModule.md index a810e41..852f937 100644 --- a/Docs/Update-GitModule.md +++ b/Docs/Update-GitModule.md @@ -12,11 +12,17 @@ This cmdlet updates previously installed PowerShell module specified by its git ## SYNTAX +### ByUri ``` Update-GitModule [-ProjectUri] [-Branch ] [-DestinationPath ] [-Force] [] ``` +### ByName +``` +Update-GitModule -Name [-Branch ] [-DestinationPath ] [-Force] [] +``` + ## DESCRIPTION This cmdlet updates previously installed PowerShell module specified by its git repository URL if repository contains newer version than installed one. @@ -92,6 +98,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Name +You can update already installed modules with their git online version if ProjectUri is specified in the module info. +To do this, just specify module name(s) with parameter -Name. + +```yaml +Type: String[] +Parameter Sets: ByName +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ProjectUri Mandatory parameter specifying URL or the repository. Multiple values are supported. @@ -102,7 +124,7 @@ You can pass this parameter also via pipeline, for example via \`Find-Module\` b ```yaml Type: String[] -Parameter Sets: (All) +Parameter Sets: ByUri Aliases: Required: True diff --git a/Private/ConvertTo-Uri.ps1 b/Private/ConvertTo-Uri.ps1 new file mode 100644 index 0000000..b55da51 --- /dev/null +++ b/Private/ConvertTo-Uri.ps1 @@ -0,0 +1,27 @@ +function ConvertTo-Uri { + # converts array of module names to uris based on projectUri field + + param ( + [Parameter(Mandatory)] + [string[]]$Name + ) + + Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names" + foreach ($N1 in $Name) { + $Module = Get-InstalledModule $N1 -ea 0 + if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0} + + if (!$Module) { + Write-Error "$FunctionName found no module $N1" + continue + } + + if (!($Module | ? ProjectUri)) { + Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information" + continue + } + + # return information to $ProjectUri variable + $Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri + } +} \ No newline at end of file diff --git a/Public/Get-GitModule.ps1 b/Public/Get-GitModule.ps1 index accc326..032042f 100644 --- a/Public/Get-GitModule.ps1 +++ b/Public/Get-GitModule.ps1 @@ -33,27 +33,7 @@ function Get-GitModule { $tmpRoot = [System.IO.Path]::GetTempPath() } - if ($Name) { - Write-Verbose -Message "$(Get-Date -f T) searching module URIs from their names" - $ProjectUri = foreach ($N1 in $Name) { - $Module = Get-InstalledModule $N1 -ea 0 - if (!$Module) {$Module = Get-Module $N1 -ListAvailable -ea 0} - - if (!$Module) { - Write-Error "$FunctionName found no module $N1" - continue - } - - if (!($Module | ? ProjectUri)) { - Write-Warning "$FunctionName found module $N1, but it has no ProjectUri information" - continue - } - - # return information to $ProjectUri variable - $Module | Sort-Object Version | Select-Object -Last 1 -ExpandProperty ProjectUri - - } - } + if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name} } diff --git a/Public/Update-GitModule.ps1 b/Public/Update-GitModule.ps1 index f3e02a1..6229472 100644 --- a/Public/Update-GitModule.ps1 +++ b/Public/Update-GitModule.ps1 @@ -5,11 +5,14 @@ function Update-GitModule { param ( - [Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)] + [Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0,ParameterSetName='ByUri')] [string[]]$ProjectUri, # https://github.com/dfinke/InstallModuleFromGitHub # https://github.com/iricigor/FIFA2018 + [Parameter(Mandatory,ParameterSetName='ByName')] + [string[]]$Name, + [string]$Branch = "master", [string]$DestinationPath = (Get-InstallPath), [switch]$Force @@ -31,6 +34,8 @@ function Update-GitModule { $tmpRoot = [System.IO.Path]::GetTempPath() } + if ($Name) {$ProjectUri = ConvertTo-Uri -Name $Name} + } PROCESS { diff --git a/Tests/functions/Update-GitModule.Tests.ps1 b/Tests/functions/Update-GitModule.Tests.ps1 index 7caec89..8a40654 100644 --- a/Tests/functions/Update-GitModule.Tests.ps1 +++ b/Tests/functions/Update-GitModule.Tests.ps1 @@ -36,6 +36,36 @@ Describe "$CommandName basic testing" -Tag 'Functionality' { } +Describe "$CommandName byName testing" -Tag 'Functionality' { + + + $moduleName = 'FIFA2018' + $moduleURL = 'https://github.com/iricigor/' + $moduleName + + $ExistingModule = Get-InstalledModule $moduleName -ea 0 + It 'Should uninstall again module if installed' -Skip:($ExistingModule -eq $null) { + {Uninstall-Module $moduleName} | Should -Not -Throw + } + + # its not so easy to remove PowerShell module + $ExistingModule = Get-Module $moduleName -ListAvailable + It 'Should delete again module if still found' -Skip:($ExistingModule -eq $null) { + {Split-Path ($ExistingModule.Path) -Parent | Remove-Item -Force -Recurse} | Should -Not -Throw + } + + It 'Should install again module from PSGallery' { + $OldProgressPreference = $ProgressPreference + $ProgressPreference = 'SilentlyContinue' + {Install-Module $moduleName -Repository PSGallery -Scope CurrentUser -Force} | Should -Not -Throw + $ProgressPreference = $OldProgressPreference + } + + It 'Should update module byName to newer version' { + Update-GitModule -Name $moduleName -Force | Should -Not -Be $null + } + +} + Describe "$CommandName error handling" -Tag 'Functionality' {