Skip to content

Commit

Permalink
2023-11-11 20:57:22
Browse files Browse the repository at this point in the history
  • Loading branch information
uidHUB committed Nov 11, 2023
1 parent 6baa057 commit e02279c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 69 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Feedback, wishes and suggestions can be sent by email.
- Constructive criticism, bug descriptions and other reports are welcome.
- Email: [[email protected]](mailto:[email protected]) / [[email protected]](mailto:[email protected]).
- Email: [[email protected]](mailto:[email protected]).

## Sources

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 iHub TO <https://ihub.to>
Copyright (c) 2023 iHub.TO <https://ihub.to>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 8 additions & 6 deletions PkgStore.Kernel.psd1
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
@{
RootModule = 'PkgStore.Kernel.psm1'
ModuleVersion = '0.0.1'
ModuleVersion = '0.1.0'
GUID = '58655ac6-8750-4397-a15f-29f9e18e257d'
Author = 'Kitsune Solar'
CompanyName = 'iHub TO'
Copyright = '(c) 2023 iHub TO. All rights reserved.'
CompanyName = 'iHub.TO'
Copyright = '(c) 2023 Library Online. All rights reserved.'
Description = 'A kernel for PowerShell modules from Package Store.'
PowerShellVersion = '7.1'
FunctionsToExport = @('Write-Msg', 'Test-Module')
PowerShellVersion = '7.2'
FunctionsToExport = @(
'Write-Msg', 'Test-Module', 'Test-Data', 'New-Data', 'Copy-Data', 'Move-Data', 'Remove-Data'
)
PrivateData = @{
PSData = @{
Tags = @('pwsh', 'kernel')
LicenseUri = 'https://github.com/pkgstore/pwsh-kernel/blob/main/LICENSE'
LicenseUri = 'https://choosealicense.com/licenses/mit/'
ProjectUri = 'https://github.com/pkgstore/pwsh-kernel'
}
}
Expand Down
162 changes: 101 additions & 61 deletions PkgStore.Kernel.psm1
Original file line number Diff line number Diff line change
@@ -1,96 +1,136 @@
<#PSScriptInfo
.VERSION 0.1.0
.GUID 58655ac6-8750-4397-a15f-29f9e18e257d
.AUTHOR Kitsune Solar
.AUTHOREMAIL [email protected]
.COMPANYNAME iHub.TO
.COPYRIGHT 2023 Kitsune Solar. All rights reserved.
.LICENSEURI https://choosealicense.com/licenses/mit/
.PROJECTURI
#>

function Write-Msg() {
<#
.SYNOPSIS
Message function.
.DESCRIPTION
#>

.PARAMETER Type
Message type.
Alias: '-T'.
param (
[Alias('T')][string]$Type,
[Alias('M')][string]$Message,
[Alias('A')][string]$Action = 'Continue'
)

.PARAMETER Message
Message body.
Alias: '-M'.
switch ($Type) {
'HL' { Write-Host "${NL}--- ${Message}".ToUpper() -ForegroundColor Blue }
'I' { Write-Information -MessageData "${Message}" -InformationAction "${Action}" }
'W' { Write-Warning -Message "${Message}" -WarningAction "${Action}" }
'E' { Write-Error -Message "${Message}" -ErrorAction "${Action}" }
default { Write-Host "${Message}" }
}
}

.PARAMETER Action
Action type.
Alias: '-A'.
function Test-Module() {
<#
.SYNOPSIS
.EXAMPLE
Write-Msg -T 'E' -M "'curl.exe' not found!" -A 'Stop'
.DESCRIPTION
#>

.LINK
Package Store: https://github.com/pkgstore
Param(
[Parameter(Mandatory)][Alias('N')][string[]]$Names
)

.NOTES
Author: Kitsune Solar <[email protected]>
#>
$Names | ForEach-Object {
if (-not (Get-Module -ListAvailable -Name "${_}")) {
Write-Error -Message "Module '${_}' not installed!" -ErrorAction 'Stop'
}
}
}

function Test-Data() {
<#
.SYNOPSIS
[CmdletBinding()]
.DESCRIPTION
#>

param (
[Alias('T')]
[string]${Type},
[Alias('T')][string]$Type,
[Alias('P')][string]$Path
)

[Alias('M')]
[string]${Message},
switch ($Type) {
'D' { $Type = 'Container' }
'F' { $Type = 'Leaf' }
}

[Alias('A')]
[string]${Action} = 'Continue'
Test-Path -LiteralPath "${Path}" -PathType "${Type}"
}

function New-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('P')][string]$Path,
[Alias('N')][string]$Name,
[Alias('A')][string]$Action = 'SilentlyContinue'
)

switch ( ${Type} ) {
'HL' {
Write-Host $( "${NL}--- ${Message}" ).ToUpper() -ForegroundColor Blue
}
'I' {
Write-Information -MessageData "${Message}" -InformationAction "${Action}"
}
'W' {
Write-Warning -Message "${Message}" -WarningAction "${Action}"
}
'E' {
Write-Error -Message "${Message}" -ErrorAction "${Action}"
}
default {
Write-Host "${Message}"
}
switch ($Type) {
'D' { $Type = 'Directory' }
'F' { $Type = 'File' }
}

New-Item -Path "${Path}" -Name "${Name}" -ItemType "${Type}" -ErrorAction "${Action}"
}

function Test-Module() {
function Copy-Data() {
<#
.SYNOPSIS
Checking if a PowerShell module is installed.
.DESCRIPTION
#>

.PARAMETER Names
Module names.
Alias: '-N'.
param (
[Alias('S')][string]$Src,
[Alias('D')][string]$Dst
)

.EXAMPLE
Test-Module -N 'PkgStore.Kernel'
Copy-Item -LiteralPath "${Src}" -Destination "${Dst}" -Force
}

.LINK
Package Store: https://github.com/pkgstore
function Move-Data() {
<#
.SYNOPSIS
.NOTES
Author: Kitsune Solar <[email protected]>
.DESCRIPTION
#>

[CmdletBinding()]
param (
[Alias('S')][string]$Src,
[Alias('D')][string]$Dst
)

Param(
[Parameter(Mandatory)]
[Alias('N')]
[string[]]${Names}
Move-Item -LiteralPath "${Src}" -Destination "${Dst}" -Force
}

function Remove-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('P')][string]$Path
)

ForEach ( ${N} in ${Names} ) {
if ( -not ( Get-Module -ListAvailable -Name "${N}" ) ) {
Write-Error -Message "Module '${N}' not installed!" -ErrorAction 'Stop'
}
}
Remove-Item -LiteralPath "${Path}" -Force
}

0 comments on commit e02279c

Please sign in to comment.