Skip to content

Commit 5e05f13

Browse files
authored
Merge pull request #14 from jimbrig/develop
feat: cleanup
2 parents 4f94fa1 + e4477e9 commit 5e05f13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+6045
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ===========================================================================
2+
# ModuleValidation.ps1 ----------------------------------------------------
3+
# ===========================================================================
4+
5+
# import ------------------------------------------------------------------
6+
# ---------------------------------------------------------------------------
7+
using namespace System.Management.Automation
8+
9+
# validation --------------------------------------------------------------
10+
# ---------------------------------------------------------------------------
11+
Class ValidateVirtualEnv : IValidateSetValuesGenerator {
12+
[String[]] GetValidValues() {
13+
return [String[]] (ValidateVirtualEnvDirectories)
14+
}
15+
}
16+
17+
# validation --------------------------------------------------------------
18+
# ---------------------------------------------------------------------------
19+
Class ValidateRequirements: IValidateSetValuesGenerator {
20+
[String[]] GetValidValues() {
21+
return [String[]] (ValidateVirtualEnvRequirement)
22+
}
23+
}
24+
25+
# validation --------------------------------------------------------------
26+
# ---------------------------------------------------------------------------
27+
Class ValidateVirtualEnvLocal: IValidateSetValuesGenerator {
28+
[String[]] GetValidValues() {
29+
return [String[]] (ValidateVirtualEnvLocalDirectories)
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# ===========================================================================
2+
# ActivatePSVirtualEnv.ps1 ------------------------------------------------
3+
# ===========================================================================
4+
5+
# function ----------------------------------------------------------------
6+
# ---------------------------------------------------------------------------
7+
function ActivateVirtualEnvAutocompletion {
8+
9+
<#
10+
.DESCRIPTION
11+
Import PSVirtualEnv activating autocompletion for validating input of module functions.
12+
13+
.OUTPUTS
14+
ScriptBlock. Scriptblock with using command.
15+
#>
16+
17+
[CmdletBinding(PositionalBinding)]
18+
19+
[OutputType([ScriptBlock])]
20+
21+
Param()
22+
23+
Process {
24+
25+
return $(Get-Command $(Join-Path -Path $Module.ClassDir -ChildPath "ModuleValidation.ps1") | Select-Object -ExpandProperty ScriptBlock)
26+
27+
}
28+
}
29+
30+
# function ----------------------------------------------------------------
31+
# ---------------------------------------------------------------------------
32+
function ValidateVirtualEnvDirectories {
33+
34+
<#
35+
.DESCRIPTION
36+
Return values for the use of validating existing virtual environments
37+
38+
.OUTPUTS
39+
System.String[]. Virtual environments
40+
#>
41+
42+
[CmdletBinding(PositionalBinding)]
43+
44+
[OutputType([System.String[]])]
45+
46+
Param()
47+
48+
Process{
49+
50+
return (Get-VirtualEnvWorkDir | Select-Object -ExpandProperty Name)
51+
52+
}
53+
}
54+
55+
# function ----------------------------------------------------------------
56+
# ---------------------------------------------------------------------------
57+
function ValidateVirtualEnvRequirement {
58+
59+
<#
60+
.DESCRIPTION
61+
Return values for the use of validating existing requirement files.
62+
63+
.OUTPUTS
64+
System.String[]. Requirement files
65+
#>
66+
67+
[CmdletBinding(PositionalBinding)]
68+
69+
[OutputType([System.String[]])]
70+
71+
Param()
72+
73+
Process{
74+
75+
$file_list = (Get-ChildItem -Path $PSVirtualEnv.RequireDir -Include "*requirements.txt" -Recurse).FullName
76+
return ($file_list | ForEach-Object {
77+
$_ -replace ($PSVirtualEnv.RequireDir -replace "\\", "\\")})
78+
79+
}
80+
}
81+
82+
# function ----------------------------------------------------------------
83+
# ---------------------------------------------------------------------------
84+
function ValidateVirtualEnvLocalDirectories {
85+
86+
<#
87+
.DESCRIPTION
88+
Return values for the use of validating existing local package folders.
89+
90+
.OUTPUTS
91+
System.String[]. Local package folder.
92+
#>
93+
94+
[CmdletBinding(PositionalBinding)]
95+
96+
[OutputType([System.String[]])]
97+
98+
Param()
99+
100+
Process{
101+
102+
$file_list = (Get-ChildItem -Path $PSVirtualEnv.LocalDir -Directory)
103+
return ($file_list | ForEach-Object {
104+
$_ -replace ($PSVirtualEnv.LocalDir -replace "\\", "\\")})
105+
}
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# ===========================================================================
2+
# Copy-VirtualEnvLocal.ps1 ------------------------------------------------
3+
# ===========================================================================
4+
5+
# function ----------------------------------------------------------------
6+
# ---------------------------------------------------------------------------
7+
function Copy-VirtualEnvLocal {
8+
9+
<#
10+
.SYNOPSIS
11+
12+
.DESCRIPTION
13+
14+
.PARAMETER Name
15+
16+
.PARAMETER All
17+
18+
.EXAMPLE
19+
PS C:\> Install-VirtualEnvPckg -Name venv
20+
21+
-----------
22+
Description
23+
24+
.INPUTS
25+
None.
26+
27+
.OUTPUTS
28+
None.
29+
#>
30+
31+
[CmdletBinding(PositionalBinding)]
32+
33+
[OutputType([Void])]
34+
35+
Param (
36+
[ValidateSet([ValidateVirtualEnv])]
37+
[Parameter(Position=1, Mandatory, ValueFromPipeline, HelpMessage="Name of the virtual environment to be changed.")]
38+
[System.String] $Name,
39+
40+
[Parameter(Position=2, Mandatory, ValueFromPipeline,HelpMessage="Specifies the path to the new location..")]
41+
[System.String] $Path,
42+
43+
[Parameter(Position=3, Mandatory=$False, ValueFromPipeline,HelpMessage="Copies files from Dest to specified virtual envrionment.")]
44+
[Switch] $Reverse
45+
)
46+
47+
Process {
48+
49+
# check whether the specified virtual environment exists
50+
if (-not (Test-VirtualEnv -Name $Name -Verbose)){
51+
Get-VirtualEnv
52+
return $Null
53+
}
54+
55+
# abort if parent folder of the destination does not exist
56+
if (-not (Test-Path -Path (Split-Path -Path $Path -Parent))) {
57+
Write-FormattedError -Message "Directory '$(Split-Path -Path $Path -Parent)' does not exist." -Module $PSVirtualEnv.Name
58+
return $Null
59+
}
60+
61+
if ((Test-Path -Path $Path) -and -not $Reverse){
62+
$choices = "&Yes", "&No"
63+
if ($Host.UI.PromptForChoice($Null, "Remove existing directory '$Path'?", $choices, 1) -eq 0) {
64+
Remove-Item -Path $Path -Recurse -Force
65+
} else {
66+
return $Null
67+
}
68+
}
69+
70+
if (-not (Test-Path -Path $Path) -and $Reverse){
71+
Write-FormattedError -Message "Directory '$Path' does not exist." -Module $PSVirtualEnv.Name
72+
return $Null
73+
}
74+
75+
Write-FormattedProcess -Message "Copying local files of virtual environment '$Name' to '$Path'." -Module $PSVirtualEnv.Name
76+
77+
$copyPath = Get-VirtualEnvLocalDir -Name $Name
78+
if ($Reverse) {
79+
$copyPath = $Path
80+
$Path = Get-VirtualEnvLocalDir -Name $Name
81+
}
82+
83+
Copy-Item -Path $copyPath -Destination $Path -Recurse -Force -ErrorAction Stop
84+
85+
Write-FormattedSuccess -Message "Files was copied." -Module $PSVirtualEnv.Name
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ===========================================================================
2+
# Edit-Requirement.ps1 -----------------------------------------------------
3+
# ===========================================================================
4+
5+
# function ----------------------------------------------------------------
6+
# ---------------------------------------------------------------------------
7+
function Edit-Requirement {
8+
9+
<#
10+
.SYNOPSIS
11+
Edit the content of an existing requirement file.
12+
13+
.DESCRIPTION
14+
Edit the content of an existing requirement file iin defined editor. All available requirement files can be accessed by autocompletion.
15+
16+
.PARAMETER Requirement
17+
18+
.EXAMPLE
19+
PS C:\> Edit-Requirement -Name venv
20+
21+
-----------
22+
Description
23+
Open the requirement file of an existing virtual environment in defined editor. All available requirement files can be accessed by autocompletion.
24+
25+
.INPUTS
26+
System.String. Relative path of existing requirement file
27+
28+
.OUTPUTS
29+
None.
30+
#>
31+
32+
[CmdletBinding(PositionalBinding)]
33+
34+
[OutputType([Void])]
35+
36+
Param(
37+
[ValidateSet([ValidateRequirements])]
38+
[Parameter(Position=1, Mandatory, ValueFromPipeline, HelpMessage="Relative path to a requirements file, or name of a virtual environment.")]
39+
[System.String] $Requirement
40+
)
41+
42+
Process {
43+
44+
# get existing requirement file
45+
if ($Requirement) {
46+
$requirement_file = Join-Path -Path $PSVirtualEnv.RequireDir -ChildPath $Requirement
47+
48+
$editor_args = $($PSVirtualEnv.EditorArgs + " " + $requirement_file)
49+
# open existing requirement file
50+
Start-Process -Path $PSVirtualEnv.Editor -NoNewWindow -Args $editor_args
51+
52+
}
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ===========================================================================
2+
# Edit-VirtualEnvConfig.ps1 ----------------------------------------------
3+
# ===========================================================================
4+
5+
# function ----------------------------------------------------------------
6+
# ---------------------------------------------------------------------------
7+
function Edit-VirtualEnvConfig {
8+
9+
<#
10+
.SYNOPSIS
11+
Edit the content of module's configuration file.
12+
13+
.DESCRIPTION
14+
Edit the content of module's configuration file in defined editor.
15+
16+
.EXAMPLE
17+
PS C:\> Edit-VirtualEnvConfig
18+
19+
-----------
20+
Description
21+
Open the content of module's configuration file in defined editor. for editing.
22+
23+
.INPUTS
24+
None.
25+
26+
.OUTPUTS
27+
None.
28+
#>
29+
30+
[CmdletBinding(PositionalBinding)]
31+
32+
[OutputType([Void])]
33+
34+
Param()
35+
36+
Process {
37+
38+
$editor_args = $($PSVirtualEnv.EditorArgs + " " + $Module.Config)
39+
40+
# open existing requirement file
41+
if (Test-Path -Path $Module.Config){
42+
Start-Process -Path $PSVirtualEnv.Editor -NoNewWindow -Args $editor_args
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)