Repository navigation
Expand file tree
/
Copy pathcore-bundle.ps1
More file actions
102 lines (84 loc) · 2.64 KB
/
Copy pathcore-bundle.ps1
File metadata and controls
102 lines (84 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function Task-IsElevated {
return (New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Task-RunElevated {
param(
[scriptblock]$block,
[object[]]$blockArguments,
[switch]$noExit
)
$command = New-PwshRunCommand $block -Arguments $blockArguments -WorkDir $PWD
if (Task-IsElevated) {
Invoke-PwshRunCommand $command
} else {
$file = Push-PwshRunCommand $command
$cmd = Task-CreateReEntryCommand -CommandFile $file -NoExit:$noExit
$cmd.StartProcess($true)
}
}
function Task-CreateReEntryCommand {
param(
[string]$commandFile,
[switch]$noExit
)
$module = (Get-Module pwshrun).Path
$arguments = New-Object System.Collections.ArrayList
if ($noExit) {
$arguments.Add("-NoExit") | Out-Null
}
$arguments.Add("-Command") | Out-Null
$arguments.Add("""& { Import-Module '$module'; Pop-PwshRunCommand '$commandFile' }""") | Out-Null
Write-Host $arguments
return New-PwshRunCommand (Get-Process -Id $pid).Path -Arguments $arguments
}
function Task-List {
Param(
[string] $bundle
)
$bundles = if ($bundle) { @($bundle) } else { $config.bundles.Keys }
$bundles | Sort-Object | ForEach-Object {
$bundleName = "[$_]".PadRight(15)
$config.bundles[$_] | Sort-Object -Property Alias | ForEach-Object {
$task = $_
$description = PwshRun-ExpandVariables $task.Description
$example = PwshRun-ExpandVariables $task.Example
Write-Output "$bundleName $($task.Alias) - $description"
Write-Output " > $example"
}
}
}
function Task-Metadata {
$config.tasks
}
function Task-ShowVars {
$config.vars
}
function Task-ShowSettings {
$config.settings
}
PwshRun-RegisterTasks "core" @(
@{
Alias = "task:list";
Command = "Task-List";
Description = "List all available tasks and their descriptions";
Example = "`$RUNNER task:list";
},
@{
Alias = "task:metadata";
Command = "Task-Metadata";
Description = "Get metadata of all available tasks";
Example = "`$RUNNER task:metadata";
},
@{
Alias = "task:vars";
Command = "Task-ShowVars";
Description = "Show all task variables";
Example = "`$RUNNER task:vars";
},
@{
Alias = "task:settings";
Command = "Task-ShowSettings";
Description = "Show all task settings";
Example = "`$RUNNER task:settings";
}
)