-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalm.swift
executable file
·179 lines (144 loc) · 4.64 KB
/
calm.swift
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/swift sh
import ArgumentParser // apple/swift-argument-parser == 0.0.2
import ShellKit // https://gitlab.com/thecb4/shellkit.git == 2630153a
import Version // mxcl/Version == 2.0.0
// import SigmaSwiftStatistics evgenyneu/SigmaSwiftStatistics == master
let env = ["PATH": "/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"]
extension Version: ExpressibleByArgument {}
extension ParsableCommand {
static func run(using arguments: [String] = []) throws {
let command = try parseAsRoot(arguments)
try command.run()
}
}
extension CommandConfiguration: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self.init(abstract: value)
}
}
struct Calm: ParsableCommand {
static var configuration = CommandConfiguration(
abstract: "A utility for performing command line work",
subcommands: [
Test.self,
Hygene.self,
LocalIntegration.self,
ContinuousIntegration.self,
Save.self,
Release.self,
Documentation.self
],
defaultSubcommand: Hygene.self
)
}
extension Calm {
struct Hygene: ParsableCommand {
static var configuration = "Perform hygene activities on the project"
func run() throws {
try ShellKit.validate(Shell.exists(at: "commit.yml"), "You need to add a commit.yml file")
try ShellKit.validate(!Shell.git_ls_untracked.contains("commit.yml"), "You need to track commit file")
try ShellKit.validate(Shell.git_ls_modified.contains("commit.yml"), "You need to update your commit file")
}
}
struct Test: ParsableCommand {
static var configuration = "Run tests"
func run() throws {
try Shell.swiftTestGenerateLinuxMain(environment: env)
try Shell.swiftFormat(version: "5.1", environment: env)
var arguments = [
"--parallel",
"--xunit-output Tests/Results.xml",
"--enable-code-coverage"
]
#if os(Linux)
arguments += ["--filter \"^(?!.*MacOS).*$\""]
#endif
try Shell.swiftTest(arguments: arguments)
}
}
struct Save: ParsableCommand {
static var configuration = "git commit activities"
func run() throws {
try Hygene.run()
try Shell.changelogger(arguments: ["log"])
try Shell.git(arguments: ["add", "-A"])
try Shell.git(arguments: ["commit", "-F", "commit.yml"])
}
}
struct LocalIntegration: ParsableCommand {
static var configuration = "Perform local integration"
@Flag(help: "Save on integration completion")
var save: Bool
func run() throws {
try Hygene.run()
try Test.run()
if save { try Save.run() }
}
}
struct ContinuousIntegration: ParsableCommand {
static var configuration = "Perform continous integration"
func run() throws {
try Test.run()
}
}
struct Documentation: ParsableCommand {
static var configuration = "Generate Documentation"
func run() throws {
try Shell.swiftDoc(
name: "ShellKit",
output: "docs",
author: "Cavelle Benjamin",
authorUrl: "https://thecb4.io",
twitterHandle: "_thecb4",
gitRepository: "https://github.com/thecb4/ShellKit"
)
}
}
}
extension Calm {
struct Release: ParsableCommand {
static var configuration = CommandConfiguration(
abstract: "Release of work",
subcommands: [
New.self,
Prepare.self,
Publish.self
],
defaultSubcommand: New.self
)
}
}
extension Calm.Release {
struct New: ParsableCommand {
static var configuration = "creates new release (tag)"
// TO-DO: move to an option group
@Argument(help: "version for the release")
var version: Version
func run() {
print("new release \(version)")
}
}
struct Prepare: ParsableCommand {
static var configuration = "prepare the current release"
@Argument(help: "summary of the release to prepare")
var summary: String
@Argument(help: "version for the release")
var version: Version
func run() throws {
let files = try Shell.git(arguments: ["status", "--untracked-files=no", "--porcelain"])
try ShellKit.validate(files.out == "", "Dirt repository. Clean it up before preparing your release")
try Shell.changelogger(arguments: ["release", "\"\(summary)\"", "--version-tag", version.description], environment: env)
try Shell.changelogger(arguments: ["markdown"])
try Shell.git(arguments: ["add", "-A"])
try Shell.git(arguments: ["commit", "-F", "commit.yml"])
}
}
struct Publish: ParsableCommand {
@Argument(help: "version for the release")
var version: Version
func run() {
print("new release \(version)")
}
}
}
Calm.main()