Skip to content

Commit 7538cbf

Browse files
committed
adding method GetFormattedLength()
1 parent 040d1e9 commit 7538cbf

File tree

9 files changed

+36
-19
lines changed

9 files changed

+36
-19
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: windows-latest
2626
steps:
2727
- name: Check out repository
28-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4
2929

3030
- name: Build module - Debug
3131
shell: pwsh
@@ -38,7 +38,7 @@ jobs:
3838
if: ${{ env.BUILD_CONFIGURATION == 'Release' }}
3939

4040
- name: Capture PowerShell Module
41-
uses: actions/upload-artifact@v3
41+
uses: actions/upload-artifact@v4
4242
with:
4343
name: PSModule
4444
path: output/*.nupkg
@@ -63,10 +63,10 @@ jobs:
6363
os: ubuntu-latest
6464

6565
steps:
66-
- uses: actions/checkout@v3
66+
- uses: actions/checkout@v4
6767

6868
- name: Restore Built PowerShell Module
69-
uses: actions/download-artifact@v3
69+
uses: actions/download-artifact@v4
7070
with:
7171
name: PSModule
7272
path: output
@@ -103,21 +103,21 @@ jobs:
103103
104104
- name: Upload Test Results
105105
if: always()
106-
uses: actions/upload-artifact@v3
106+
uses: actions/upload-artifact@v4
107107
with:
108108
name: Unit Test Results (${{ matrix.info.name }})
109109
path: ./output/TestResults/Pester.xml
110110

111111
- name: Upload Coverage Results
112112
if: always() && !startsWith(github.ref, 'refs/tags/v')
113-
uses: actions/upload-artifact@v3
113+
uses: actions/upload-artifact@v4
114114
with:
115115
name: Coverage Results (${{ matrix.info.name }})
116116
path: ./output/TestResults/Coverage.xml
117117

118118
- name: Upload Coverage to codecov
119119
if: always() && !startsWith(github.ref, 'refs/tags/v')
120-
uses: codecov/codecov-action@v3
120+
uses: codecov/codecov-action@v4
121121
with:
122122
files: ./output/TestResults/Coverage.xml
123123
flags: ${{ matrix.info.name }}
@@ -131,7 +131,7 @@ jobs:
131131
runs-on: windows-latest
132132
steps:
133133
- name: Restore Built PowerShell Module
134-
uses: actions/download-artifact@v3
134+
uses: actions/download-artifact@v4
135135
with:
136136
name: PSModule
137137
path: ./

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
- __02/26/2024__
4+
- Added method `.GetFormattedLength()`. Outputs the friendly `.Length` representation of `PSTreeFile` and `PSTreeDirectory` instances.
5+
6+
```powershell
7+
PS ..\PSTree> (Get-PSTree D:\ -RecursiveSize -Depth 0).GetFormattedLength()
8+
629.59 GB
9+
```
10+
311
- __10/05/2023__
412
- Added Parameter `-Include`. Works very similar to `-Exclude`, the patterns are evaluated against the items `.FullName` property, however this parameter targets only files (`FileInfo` instances).
513

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end {
5858
$dotnetTools = @(dotnet tool list --global) -join "`n"
5959
if (-not $dotnetTools.Contains('coverlet.console')) {
6060
Write-Host 'Installing dotnet tool coverlet.console'
61-
dotnet tool install --global coverlet.console
61+
dotnet tool install --global coverlet.console --version 6.0.0
6262
}
6363

6464
$invokeBuildSplat = @{

module/PSTree.Format.ps1xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<PropertyName>Mode</PropertyName>
3535
</TableColumnItem>
3636
<TableColumnItem>
37-
<ScriptBlock>[PSTree.Internal._FormattingInternals]::GetFormattedLength($_.Length)</ScriptBlock>
37+
<ScriptBlock>$_.GetFormattedLength()</ScriptBlock>
3838
</TableColumnItem>
3939
<TableColumnItem>
4040
<PropertyName>Hierarchy</PropertyName>

module/PSTree.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'bin/netstandard2.0/PSTree.dll'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2.1.15'
14+
ModuleVersion = '2.1.16'
1515

1616
# Supported PSEditions
1717
# CompatiblePSEditions = @()

src/PSTree/PSTreeFileSystemInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ protected PSTreeFileSystemInfo(string hierarchy, string source)
1515
Hierarchy = hierarchy;
1616
Source = source;
1717
}
18+
19+
public string GetFormattedLength() =>
20+
Internal._FormattingInternals.GetFormattedLength(Length);
1821
}

src/PSTree/PathExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace PSTree;
1111
internal static class PathExtensions
1212
{
1313
[ThreadStatic]
14-
private static readonly List<string> s_normalizedPaths = new();
14+
private static List<string>? s_normalizedPaths;
1515

1616
private static readonly char[] _dirSeparator = @"\/".ToCharArray();
1717

@@ -22,9 +22,11 @@ internal static string[] NormalizePath(
2222
bool throwOnInvalidPath = false,
2323
bool throwOnInvalidProvider = false)
2424
{
25+
s_normalizedPaths ??= new();
26+
s_normalizedPaths.Clear();
27+
2528
Collection<string> resolvedPaths;
2629
ProviderInfo provider;
27-
s_normalizedPaths.Clear();
2830

2931
foreach (string path in paths)
3032
{

tests/PSTreeDirectory.ps1 renamed to tests/PSTreeDirectory.tests.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ Import-Module ([System.IO.Path]::Combine($PSScriptRoot, 'shared.psm1'))
99
Describe 'PSTreeDirectory' {
1010
It 'Can enumerate Files with .EnumerateFiles()' {
1111
($testPath | Get-PSTree -Depth 0).EnumerateFiles() |
12-
ForEach-Object GetType |
13-
Should -Be ([System.IO.FileInfo])
12+
Should -BeOfType ([System.IO.FileInfo])
1413
}
1514

1615
It 'Can enumerate Directories with .EnumerateDirectories()' {
1716
($testPath | Get-PSTree -Depth 0).EnumerateDirectories() |
18-
ForEach-Object GetType |
19-
Should -Be ([System.IO.DirectoryInfo])
17+
Should -BeOfType ([System.IO.DirectoryInfo])
2018
}
2119

2220
It 'Can enumerate File System Infos with .EnumerateFileSystemInfos()' {
@@ -26,9 +24,10 @@ Describe 'PSTreeDirectory' {
2624
}
2725

2826
It 'Can enumerate its parent directories with .GetParents()' {
29-
$parent = ($testPath | Get-PSTree -Depth 0).Parent
27+
$treedir = $testPath | Get-PSTree -Depth 0
28+
$parent = $treedir.Parent
3029
$parent | Should -BeOfType ([System.IO.DirectoryInfo])
3130
$paths = $parent.FullName.Split([System.IO.Path]::DirectorySeparatorChar)
32-
$parent.GetParents() | Should -HaveCount $paths.Count
31+
$treedir.GetParents() | Should -HaveCount $paths.Count
3332
}
3433
}

tests/PSTreeFileSystemInfo_T.tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ Describe 'PSTreeFileSystemInfo<T>' {
6565
$instance.LastAccessTime | Should -BeOfType ([datetime])
6666
$instance.LastWriteTimeUtc | Should -BeOfType ([datetime])
6767
}
68+
69+
It 'GetFormattedLength() outputs friendly length' {
70+
$pattern = '(?:{0}$)' -f ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' -join '|')
71+
(Get-PSTree $testPath).GetFormattedLength() | Should -Match $pattern
72+
}
6873
}

0 commit comments

Comments
 (0)