Skip to content

Commit

Permalink
Merge pull request #4 from ethanbergstrom/packageTypeCorrection
Browse files Browse the repository at this point in the history
Attempt at fixing formulae as casks
  • Loading branch information
ethanbergstrom authored Sep 3, 2022
2 parents 002244a + ad9d215 commit 2dc54c6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.5] - 2022-09-03
### Added
- Support for forced installation
### Fixed
- Formulae showing up as casks

## [0.0.4] - 2022-07-02
### Added
- Additional tap metadata retrieval
Expand Down
16 changes: 13 additions & 3 deletions src/Croze.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ $Commands = @(
Description = 'Install a new package with Homebrew'
OriginalCommandElements = @('install')
OutputHandlers = $PackageInstallHandlers
Parameters = @(
@{
Name = 'Force'
OriginalName = '--force'
ParameterType = 'switch'
Description = 'Force'
}
)
},
@{
Verb = 'Get'
Expand Down Expand Up @@ -188,7 +196,8 @@ $Commands = @(

# Determine the range of formulae output based on whether we also have cask output
$formulaeEndIndex = $(
if ($formulaeStartIndex) {
# Cant use a standard check here, because a valid value could be '0', which would evaluate to $false
if ($formulaeStartIndex -ne $null) {
if ($casksStartIndex) {
# Stop capturing formulae output two rows before the start of the Cask index
$casksStartIndex-2
Expand All @@ -200,7 +209,8 @@ $Commands = @(
}
)

if ($formulaeStartIndex) {
# Cant use a standard check here, because a valid value could be '0', which would evaluate to $false
if ($formulaeStartIndex -ne $null) {
$output[($formulaeStartIndex+1)..$formulaeEndIndex] | ForEach-Object {
[PSCustomObject]@{
Name = $_
Expand All @@ -209,7 +219,7 @@ $Commands = @(
}
}

if ($casksStartIndex -ne -1) {
if ($casksStartIndex -ne $null) {
$output[($casksStartIndex+1)..($output.Length)] | ForEach-Object {
[PSCustomObject]@{
Name = $_
Expand Down
2 changes: 1 addition & 1 deletion src/Croze.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'Croze.psm1'
ModuleVersion = '0.0.4'
ModuleVersion = '0.0.5'
GUID = '46caec03-e808-4fa2-b464-14677bb60c52'
Author = 'Ethan Bergstrom'
Copyright = '2022'
Expand Down
22 changes: 11 additions & 11 deletions test/Croze.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Describe 'basic package search operations' {
Describe 'DSC-compliant package installation and uninstallation' {
Context 'without additional arguments' {
BeforeAll {
$package = 'tmux'
$package = 'ipinfo'
}

It 'searches for the latest version of a package' {
Expand All @@ -39,14 +39,14 @@ Describe 'DSC-compliant package installation and uninstallation' {
}
Context 'with formulae' {
BeforeAll {
$package = 'tmux'
$package = 'ipinfo'
}

It 'searches for the latest version of a package' {
Find-HomebrewPackage -Name $package -Formula | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
}
It 'silently installs the latest version of a package' {
Install-HomebrewPackage -Name $package -Formula | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
Install-HomebrewPackage -Name $package -Formula -Force | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
}
It 'finds the locally installed package just installed' {
Get-HomebrewPackage -Name $package -Formula | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
Expand All @@ -67,7 +67,7 @@ Describe 'DSC-compliant package installation and uninstallation' {
Find-HomebrewPackage -Name $package -Cask | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
}
It 'silently installs the latest version of a package' {
Install-HomebrewPackage -Name $package -Cask | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
Install-HomebrewPackage -Name $package -Cask -Force | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
}
It 'finds the locally installed package just installed' {
Get-HomebrewPackage -Name $package -Cask | Where-Object {$_.Name -eq $package} | Should -HaveCount 1
Expand All @@ -84,7 +84,7 @@ Describe 'DSC-compliant package installation and uninstallation' {
Describe 'pipline-based package installation and uninstallation' {
Context 'without additional arguments' {
BeforeAll {
$package = 'tmux'
$package = 'ipinfo'
}

It 'searches for and silently installs the latest version of a package' {
Expand All @@ -96,11 +96,11 @@ Describe 'pipline-based package installation and uninstallation' {
}
Context 'with formulae' {
BeforeAll {
$package = 'tmux'
$package = 'ipinfo'
}

It 'searches for and silently installs the latest version of a package' {
Find-HomebrewPackage -Name $package -Formula | Where-Object {$_.Name -eq $package} | Install-HomebrewPackage | Should -HaveCount 1
Find-HomebrewPackage -Name $package -Formula | Where-Object {$_.Name -eq $package} | Install-HomebrewPackage -Force | Should -HaveCount 1
}
It 'finds and silently uninstalls the locally installed package just installed' {
{Get-HomebrewPackage -Name $package -Formula | Uninstall-HomebrewPackage} | Should -Not -Throw
Expand All @@ -112,7 +112,7 @@ Describe 'pipline-based package installation and uninstallation' {
}

It 'searches for and silently installs the latest version of a package' {
Find-HomebrewPackage -Name $package -Cask | Where-Object {$_.Name -eq $package} | Install-HomebrewPackage | Should -HaveCount 1
Find-HomebrewPackage -Name $package -Cask | Where-Object {$_.Name -eq $package} | Install-HomebrewPackage -Force | Should -HaveCount 1
}
It 'finds and silently uninstalls the locally installed package just installed' {
{Get-HomebrewPackage -Name $package -Cask | Uninstall-HomebrewPackage} | Should -Not -Throw
Expand All @@ -124,7 +124,7 @@ Describe 'pipline-based package installation and uninstallation' {
# Describe 'package upgrade' {
# Context 'with formulae' {
# BeforeAll {
# $package = 'tmux'
# $package = 'ipinfo'
# $version = '1.95'
# Install-HomebrewPackage -Name $package -Version $version
# }
Expand Down Expand Up @@ -186,7 +186,7 @@ Describe "multi-source support" {
Describe 'package metadata retrieval' {
Context 'without additional arguments' {
BeforeAll {
$package = 'tmux'
$package = 'ipinfo'
}

It 'returns package metadata' {
Expand All @@ -195,7 +195,7 @@ Describe 'package metadata retrieval' {
}
Context 'with formulae' {
BeforeAll {
$package = 'tmux'
$package = 'ipinfo'
}

It 'returns package metadata' {
Expand Down

0 comments on commit 2dc54c6

Please sign in to comment.