Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/source-shell-functions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Shell-Functions source checks
on:
push:
branches: [fix/build-shell-functions]
pull_request:
branches: [Shell-Functions/develop]
permissions:
contents: read
jobs:
source:
uses: stadub/PowershellScripts/.github/workflows/validate-module-source.yml@d3fa5897213e3ff4e0d64897559bdfb516356512
with:
module: Shell-Functions
source_sha: ${{ github.event.pull_request.head.sha || github.sha }}
automation_sha: d3fa5897213e3ff4e0d64897559bdfb516356512
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# File types to ignore globally
.history
.vscode
TestResults/
17 changes: 17 additions & 0 deletions Shell-Functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Shell-Functions source module

Import Shell-Function.psd1 to load the existing shell filters and helpers. The
manifest previously imported nothing and exported no commands. The loader now
exports seven existing functions and seven aliases without global-scope alias
writes. The stale pb alias is omitted because Export-Module is absent, and the protected
PowerShell fl (Format-List) alias is preserved; ln/mklink call the link helper.

This source repair corrects Split-String's accidental method-property access,
binds New-FileSystemLink to its existing LinkType enum, and maps enum values to
PowerShell provider item types. The spelling of existing public command/parameter
names is retained. Windows batch/Visual Studio helpers are not executed at import.

Run Shell-Function.Tests.ps1 with Pester 4.10.1. CI tests imports/exports, real text
filters and mocked link-provider arguments; it never runs cmd, changes Visual
Studio state, creates links or invokes the interactive prompt. This module has
no configured Gallery publication or release package.
6 changes: 3 additions & 3 deletions Shell-Functions/Shell-Alias.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Set-Alias ln New-FileSystemLink -Scope Global
Set-Alias mklink New-FileSystemLink -Scope Global
Set-Alias which Get-Command -Scope Global
Set-Alias ln New-FileSystemLink
Set-Alias mklink New-FileSystemLink
Set-Alias which Get-Command
42 changes: 42 additions & 0 deletions Shell-Functions/Shell-Function.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
$manifest = Join-Path $PSScriptRoot 'Shell-Function.psd1'
Import-Module $manifest -Force -ErrorAction Stop
Describe 'Shell source imports and filters' {
It 'exports callable functions and resolvable aliases from its manifest' {
$module = Get-Module 'Shell-Function'
$module.ExportedFunctions.Count | Should -Be 7
$module.ExportedAliases.Count | Should -Be 7
$module.ExportedAliases.ContainsKey('pb') | Should -BeFalse
(Get-Alias fl).Definition | Should -BeExactly 'Format-List'
foreach ($alias in $module.ExportedAliases.Values) {
Get-Command $alias.Definition -ErrorAction Stop | Should -Not -BeNullOrEmpty
}
(Get-Command New-FileSystemLink).Parameters['type'].ParameterType.Name | Should -BeExactly 'LinkType'
}
It 'filters matching pipeline lines' {
@('Alpha', 'Beta' | Get-SearchAndPrint 'alpha').Count | Should -Be 1
'Alpha', 'Beta' | grep 'alpha' | Select-Object -ExpandProperty Line | Should -BeExactly 'Alpha'
}
It 'splits pipeline strings using the requested literal separator' {
('a,b' | cut ',') -join '|' | Should -BeExactly 'a|b'
('a::b::' | Split-String '::') -join '|' | Should -BeExactly 'a|b|'
('a b' | Split-String) -join '|' | Should -BeExactly 'a|b'
}
}
InModuleScope 'Shell-Function' {
Describe 'Link provider argument contracts' {
It 'maps <Type> without creating a link' -TestCases @(
@{ Type='Symbolic'; Expected='SymbolicLink' }
@{ Type='Hard'; Expected='HardLink' }
@{ Type='Junction'; Expected='Junction' }
) {
param($Type, $Expected)
Mock New-Item { [pscustomobject]@{ Path=$Path; ItemType=$ItemType; Value=$Value } }
$result = New-FileSystemLink -source 'source file' -destanation 'dest path' -type $Type
$result.Path | Should -BeExactly 'dest path'
$result.Value | Should -BeExactly 'source file'
$result.ItemType | Should -BeExactly $Expected
Assert-MockCalled New-Item -Times 1 -Exactly -Scope It
}
}
}
Remove-Module 'Shell-Function' -Force
12 changes: 7 additions & 5 deletions Shell-Functions/Shell-Function.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ filter Get-SearchAndPrint() {

filter Split-String() {
Param ([string]$separator = $null)
$_.Split | select-string -pattern $separator
if ([string]::IsNullOrEmpty($separator)) { $_.Split() }
else { $_.Split([string[]]@($separator), [StringSplitOptions]::None) }
}

function Get-Batchfile ($file) {
Expand Down Expand Up @@ -107,10 +108,11 @@ function New-FileSystemLink {
[string]$destanation = $((Get-Location).Path),

[Parameter(Position = 2, ParameterSetName = 'Positional', Mandatory = $true)]
[ServerType]$type = [LinkType]::Symbolic
[LinkType]$type = [LinkType]::Symbolic

)
New-Item -Path $destanation -ItemType $type -Value $source
$itemType = @{ Symbolic = 'SymbolicLink'; Hard = 'HardLink'; Junction = 'Junction' }[$type.ToString()]
New-Item -Path $destanation -ItemType $itemType -Value $source
}

function Propmpt {
Expand All @@ -133,6 +135,6 @@ Set-Alias grep Get-SearchAndPrint
Set-Alias cut Split-String
Set-Alias VsVars32 Initialize-VisualStudioEnvieronment
Set-Alias ga Get-CmdletAlias
Set-Alias fl New-FileSystemLink
Set-Alias pb Export-Module
# Keep PowerShell's protected fl (Format-List) alias. Use ln or mklink instead.
# Export-Module is not part of this module; do not create a dangling pb alias.

8 changes: 4 additions & 4 deletions Shell-Functions/Shell-Function.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@{

# Script module or binary module file associated with this manifest.
# RootModule = ''
RootModule = 'Shell-Function.psm1'

# Version number of this module.
ModuleVersion = '0.0.1'
Expand Down Expand Up @@ -69,16 +69,16 @@ Copyright = '(c) Dmitry.Stadub. All rights reserved.'
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()
FunctionsToExport = @('Get-SearchAndPrint', 'Split-String', 'Get-Batchfile', 'Initialize-VisualStudioEnvieronment', 'Get-CmdletAlias', 'New-FileSystemLink', 'Propmpt')

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = '*'
VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()
AliasesToExport = @('grep', 'cut', 'VsVars32', 'ga', 'ln', 'mklink', 'which')

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down
4 changes: 4 additions & 0 deletions Shell-Functions/Shell-Function.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
. (Join-Path $PSScriptRoot 'Shell-Function.ps1')
. (Join-Path $PSScriptRoot 'Shell-Alias.ps1')
# pb targets a removed Export-Module command; do not expose a dangling alias.
Export-ModuleMember -Function Get-SearchAndPrint, Split-String, Get-Batchfile, Initialize-VisualStudioEnvieronment, Get-CmdletAlias, New-FileSystemLink, Propmpt -Alias grep, cut, VsVars32, ga, ln, mklink, which
Loading