Skip to content

Commit 17b9d5a

Browse files
Merge pull request #59 from PowershellFrameworkCollective/Development
2.1.28
2 parents 3e71e51 + 426eb40 commit 17b9d5a

26 files changed

+497
-527
lines changed

PSUtil/PSUtil.psd1

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
# Modules that must be imported into the global environment prior to importing
2727
# this module
2828
RequiredModules = @(
29-
@{ ModuleName='PSFramework'; ModuleVersion='1.0.35' }
29+
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.1.59' }
30+
@{ ModuleName = 'string'; ModuleVersion = '0.6.1' }
3031
)
3132

3233
# Assemblies that must be loaded prior to importing this module
@@ -36,25 +37,24 @@
3637
# TypesToProcess = @('xml\PSUtil.Types.ps1xml')
3738

3839
# Format files (.ps1xml) to be loaded when importing this module
39-
# FormatsToProcess = @('xml\PSUtil.Format.ps1xml')
40+
FormatsToProcess = @('xml\PSUtil.Format.ps1xml')
4041

4142
# Functions to export from this module
4243
FunctionsToExport = @(
43-
'Add-PSUString'
4444
'Backup-PSULocation'
4545
'Convert-PSUObject'
4646
'Expand-PSUObject'
47-
'Format-PSUString'
4847
'Get-PSUPathAlias'
4948
'Invoke-PSUDesktop'
5049
'Invoke-PSUExplorer'
5150
'Invoke-PSUTemp'
52-
'Join-PSUString'
5351
'New-PSUDirectory'
52+
'Out-PSUVariable'
5453
'Register-PSUObjectConversion'
5554
'Register-PSUObjectExpansion'
55+
'Read-PSUKnowledge'
56+
'Remove-PSUKnowledge'
5657
'Remove-PSUPathAlias'
57-
'Remove-PSUString'
5858
'Select-PSUFunctionCode'
5959
'Select-PSUObjectSample'
6060
'Set-PSUDrive'
@@ -63,9 +63,8 @@
6363
'Set-PSUPathAlias'
6464
'Set-PSUPrompt'
6565
'Set-PSUShell'
66-
'Set-PSUString'
67-
'Split-PSUString'
6866
'Start-PSUTimer'
67+
'Write-PSUKnowledge'
6968
)
7069

7170
# Cmdlets to export from this module
@@ -76,36 +75,50 @@
7675

7776
# Aliases to export from this module
7877
AliasesToExport = @(
79-
'a',
80-
'add',
81-
'bu',
82-
'c',
83-
'cast',
84-
'convert',
85-
'desktop',
86-
'ec',
87-
'ex',
88-
'exp',
89-
'explorer',
90-
'format',
91-
'grep',
92-
'ic',
93-
'inspect',
94-
'ix',
95-
'join',
96-
'm',
97-
'mcd',
98-
'new',
99-
'ocb',
100-
'replace',
101-
's',
102-
'set-as',
103-
'split',
104-
'spo',
105-
'temp',
106-
'timer',
107-
'trim',
108-
'v',
78+
'a'
79+
'add'
80+
'Add-PSUString'
81+
'bu'
82+
'c'
83+
'cast'
84+
'cfj'
85+
'convert'
86+
'ctj'
87+
'desktop'
88+
'ec'
89+
'ex'
90+
'exp'
91+
'explorer'
92+
'format'
93+
'Format-PSUString'
94+
'grep'
95+
'ic'
96+
'inspect'
97+
'ix'
98+
'join'
99+
'Join-PSUString'
100+
'learn'
101+
'm'
102+
'mcd'
103+
'new'
104+
'ocb'
105+
'ov'
106+
'page'
107+
'rdk'
108+
'read'
109+
'Remove-PSUString'
110+
'replace'
111+
's'
112+
'Select-PSUObject'
113+
'set-as'
114+
'Set-PSUString'
115+
'split'
116+
'Split-PSUString'
117+
'spo'
118+
'temp'
119+
'timer'
120+
'trim'
121+
'v'
109122
'wrap'
110123
)
111124

PSUtil/changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Changelog
2+
## 2.1.28 (2020-03-21)
3+
- New: Component: Knowledge - store and search knowledge
4+
- New: Command: Read-PSUKnowledge (read, page, learn) - retrieves stored knowledge
5+
- New: Command: Write-PSUKnowledge - writes knowledge for later retrieval
6+
- New: Command: Remove-PSUKnowledge - removes knowledge from storage. Use on alternative facts.
7+
- New: Command: Out-PSUVariable - writes input to variable, enabling variable assignment at the end of the pipeline
8+
- New: Alias rmn --> Remove-PSFNull
9+
- New: Dependency on string module, dropping own string cmdlets, ading aliases for compatibility
10+
- New: Adding psf tab completion for property names to common object commands
11+
212
## 2.0.20 (2019-09-18)
313
- New: Command: Set-PSUPrompt - Applies a prompt from a set of pre-defined prompts
4-
- New: COmmand: Register-PSUObjectExpansion - Registers custom expansion rules for Expand-PSUObject
14+
- New: Command: Register-PSUObjectExpansion - Registers custom expansion rules for Expand-PSUObject
515
- Upd: Start-PSUTimer - Added -MinFrequency and -MaxFrequency parameters.
616
- Upd: Start-PSUTimer - Refactored parameter order, rationalized message handling
717
- Upd: Invoke-PSUExplorer - Enabled opt-in exceptions and improved path resolution

PSUtil/en-us/strings.psd1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@{
2+
'Set-PSUKnowledge.Library.Path.CreationFailed' = 'Failed to create library path: {0}. Validate the path and ensure the necessary permissions are in place.' # $libraryPath
3+
'Set-PSUKnowledge.Book.ImportFailed' = 'Failed to read the book "{0}" from "{1}"' # $Book, $bookPath
4+
'Set-PSUKnowledge.Book.ExportFailed' = 'Failed to write the page "{0}" into the book "{1}" at "{2}"' # $Name, $Book, $bookPath
5+
}

PSUtil/functions/explorer/Backup-PSULocation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
$Levels = (Get-PSFConfigValue -FullName 'PSUtil.Path.BackupStepsDefault' -Fallback 1)
2929
)
3030

31-
Set-Location -Path (,".." * $Levels | Join-PSUString -With ([System.IO.Path]::DirectorySeparatorChar))
31+
Set-Location -Path (,".." * $Levels | Join-String -With ([System.IO.Path]::DirectorySeparatorChar))
3232
}
3333

3434
Import-PSUAlias -Name "bu" -Command "Backup-PSULocation"
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
function Read-PSUKnowledge
2+
{
3+
<#
4+
.SYNOPSIS
5+
Searches for knowledge.
6+
7+
.DESCRIPTION
8+
Searches for knowledge.
9+
Generally, knowledge must first be generated using Write-PSUKnowledge.
10+
This allows these functions to server as a searchable notes section right within your console.
11+
12+
However, there might be some other ways to seek knowledge ...
13+
14+
.PARAMETER Name
15+
The name of the knowledge entry.
16+
17+
.PARAMETER Tags
18+
Tags to search by. At least one of the specified tags must be contained.
19+
20+
.PARAMETER Pattern
21+
Search Name and text of the page by using this regex pattern.
22+
23+
.PARAMETER Book
24+
The book to search in.
25+
By default you only have one and don't need to worry about this.
26+
27+
.PARAMETER Online
28+
Mysterious parameter. I wonder what it does ...
29+
30+
.EXAMPLE
31+
PS C:\> Read-PSUKnowledge
32+
33+
Lists all knowledge entries.
34+
35+
.EXAMPLE
36+
PS C:\> Read-PSUKnowledge -Tags DNS
37+
38+
Lists all knowledge entries with the tag "DNS"
39+
40+
.EXAMPLE
41+
PS C:\> read -p ldap
42+
43+
Lists all knowledge entries with the string "ldap" in name or text.
44+
#>
45+
[CmdletBinding()]
46+
param (
47+
[parameter(Position = 0)]
48+
[Alias('Page')]
49+
[string]
50+
$Name = '*',
51+
52+
[string[]]
53+
$Tags,
54+
55+
[Alias('p','f','filter')]
56+
[string]
57+
$Pattern = '.',
58+
59+
[string]
60+
$Book = '*',
61+
62+
[switch]
63+
$Online
64+
)
65+
66+
begin
67+
{
68+
$libraryPath = Get-PSFConfigValue -FullName 'PSUtil.Knowledge.LibraryPath'
69+
}
70+
process
71+
{
72+
# Gimmick: Search in wikipedia
73+
if ($Online)
74+
{
75+
$url = "https://en.wikipedia.org/wiki/Special:Search/$Name"
76+
Start-Process $url
77+
return
78+
}
79+
80+
if (-not (Test-Path -Path $libraryPath)) { return }
81+
82+
foreach ($bookFile in (Get-ChildItem -Path $libraryPath -Filter *.json))
83+
{
84+
$bookName = [System.Text.Encoding]::UTF8.GetString(([convert]::FromBase64String($bookFile.BaseName)))
85+
if ($bookName -notlike $Book) { continue }
86+
87+
$data = Get-Content -Path $bookFile.FullName | ConvertFrom-Json
88+
89+
foreach ($page in $data)
90+
{
91+
if ($page.Name -notlike $Name) { continue }
92+
if ($Tags -and -not ($Tags | Where-Object { $_ -in $page.Tags })) { continue }
93+
94+
if ($Pattern -ne '.')
95+
{
96+
$matched = $false
97+
if ($page.Name -match $Pattern) { $matched = $true }
98+
elseif ($page.Text -match $Pattern) { $matched = $true }
99+
if (-not $matched) { continue }
100+
}
101+
102+
$page | Select-PSFObject -KeepInputObject -TypeName 'PSUtil.Knowledge.Page'
103+
}
104+
}
105+
}
106+
}
107+
Import-PSUAlias -Name 'read' -Command Read-PSUKnowledge
108+
Import-PSUAlias -Name 'rdk' -Command Read-PSUKnowledge
109+
Import-PSUAlias -Name 'page' -Command Read-PSUKnowledge
110+
Import-PSUAlias -Name 'learn' -Command Read-PSUKnowledge
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
function Remove-PSUKnowledge
2+
{
3+
<#
4+
.SYNOPSIS
5+
Removes pages from the books of your holy console library of knowledge.
6+
7+
.DESCRIPTION
8+
Removes pages from the books of your holy console library of knowledge.
9+
Contribute new knowledge by using Write-PSUKnowledge or search it by using Read-PSUKnowlege.
10+
11+
.PARAMETER Name
12+
The name of the page to rip out.
13+
14+
.PARAMETER Book
15+
The book of knowledge to deface.
16+
Defaults to the book specified under the 'PSUtil.Knowledge.DefaultBook' configuration setting.
17+
It will look for books in your library path, which can be specified under 'PSUtil.Knowledge.LibraryPath'.
18+
19+
.EXAMPLE
20+
PS C:\> Remove-PSUKnowledge -Name 'DNS for Dummies'
21+
22+
Rips out the page 'DNS for Dummies' from your default book.
23+
#>
24+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
25+
[CmdletBinding()]
26+
param (
27+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
28+
[Alias('page')]
29+
[string[]]
30+
$Name,
31+
32+
[Parameter(ValueFromPipelineByPropertyName = $true)]
33+
[string]
34+
$Book = (Get-PSFConfigValue -FullName 'PSUtil.Knowledge.DefaultBook')
35+
)
36+
37+
begin
38+
{
39+
$libraryPath = Get-PSFConfigValue -FullName 'PSUtil.Knowledge.LibraryPath'
40+
}
41+
process
42+
{
43+
if (-not (Test-Path -Path $libraryPath)) { return }
44+
45+
$bookName = '{0}.json' -f [System.Text.Encoding]::UTF8.GetBytes($Book)
46+
$bookPath = Join-Path $libraryPath $bookName
47+
48+
if (-not (Test-Path -Path $bookPath)) { return }
49+
50+
$pageEntries = Get-Content -Path $bookPath | ConvertFrom-Json
51+
$pageEntries = $pageEntries | Where-Object Name -notin $Name
52+
$pageEntries | ConvertTo-Json | Set-Content -Path $bookPath
53+
}
54+
}

0 commit comments

Comments
 (0)