-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.ps1
112 lines (102 loc) · 2.58 KB
/
tools.ps1
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
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env pwsh
# Copyright 2021 Vincent Fiestada
. (Join-Path 'tools' 'std' 'std.ps1')
. (Join-Path 'tools' 'std' 'help.ps1')
. (Join-Path 'tools' 'go' 'install.ps1')
. (Join-Path 'tools' 'go' 'format.ps1')
. (Join-Path 'tools' 'go' 'check.ps1')
. (Join-Path 'tools' 'go' 'test.ps1')
. (Join-Path 'tools' 'go' 'run.ps1')
. (Join-Path 'tools' 'go' 'publish.ps1')
. (Join-Path 'tools' 'go' 'benchmark.ps1')
function Invoke-Tools {
param(
[Parameter(ValueFromPipeline=$true)]
[String] $Command = '',
[Parameter(ValueFromPipeline=$true)]
[String[]] $Arguments = @()
)
if ($null -eq $Command.Length) {
Write-Error 'command required'
exit [Errors]::NoCommand
}
$tools = @(
[Tool]::new(
'help',
'list available commands',
{
Get-Toolkit $tools
}
),
[Tool]::new(
'install',
'check dev environment and install project',
{
Install-GoProject
}
),
[Tool]::new(
'format',
'apply style guide and tidy dependencies',
{
Invoke-GoFormat
}
),
[Tool]::new(
'check',
'detect issues using linters',
{
Invoke-GoChecks
}
),
[Tool]::new(
'fix',
'apply autofixes suggested by linters',
{
Invoke-GoChecks -Fix
}
),
[Tool]::new(
'test',
'run all tests with coverage',
{
Invoke-GoTests
}
),
[Tool]::new(
'benchmark',
'run all benchmark tests',
{
Invoke-GoBenchmarks
}
),
[Tool]::new(
'demo',
'compile and run demo',
{
Invoke-GoPackage ./demo $Arguments
}
),
[Tool]::new(
'publish',
"publish `e[3mversion`e[3m",
'publish a version to pkg.go.dev',
{
Publish-GoModule $Arguments[0]
}
)
)
$target = $tools | Where-Object { $_.Command -eq $Command }
if (-not $target) {
Write-Error "invalid command '$Command'"
exit [Error]::InvalidCommand
}
Invoke-Command -ScriptBlock $target.Script
}
enum Error {
NoCommand = 1
}
$command = $args[0]
$arguments = $args[1..($args.Length - 1)]
Invoke-Tools $command $arguments
exit 0