Skip to content

Commit 4c779ba

Browse files
committed
Use Commander* to generate the variadic-ish commands
*Commander now depends on Commander 💥
1 parent 198341f commit 4c779ba

File tree

9 files changed

+652
-163
lines changed

9 files changed

+652
-163
lines changed

Commander.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
2714C5591BB5403400E0EB6A /* Commands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2714C5581BB5403300E0EB6A /* Commands.swift */; settings = {ASSET_TAGS = (); }; };
1011
2720BDED1BB348BC00C09984 /* ArgumentDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2720BDEC1BB348BC00C09984 /* ArgumentDescription.swift */; settings = {ASSET_TAGS = (); }; };
1112
2768A2241BACC38C00F994EE /* Commander.h in Headers */ = {isa = PBXBuildFile; fileRef = 2768A2231BACC38C00F994EE /* Commander.h */; settings = {ATTRIBUTES = (Public, ); }; };
1213
2768A22B1BACC38C00F994EE /* Commander.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2768A2201BACC38C00F994EE /* Commander.framework */; settings = {ASSET_TAGS = (); }; };
@@ -34,6 +35,7 @@
3435
/* End PBXContainerItemProxy section */
3536

3637
/* Begin PBXFileReference section */
38+
2714C5581BB5403300E0EB6A /* Commands.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Commands.swift; sourceTree = "<group>"; };
3739
2720BDEC1BB348BC00C09984 /* ArgumentDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArgumentDescription.swift; sourceTree = "<group>"; };
3840
27593EE51BB335590018278E /* UniversalFramework_Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = UniversalFramework_Base.xcconfig; sourceTree = "<group>"; };
3941
27593EE61BB335590018278E /* UniversalFramework_Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = UniversalFramework_Framework.xcconfig; sourceTree = "<group>"; };
@@ -115,6 +117,7 @@
115117
2720BDEC1BB348BC00C09984 /* ArgumentDescription.swift */,
116118
279256A91BB3226E00E66B9E /* CommandType.swift */,
117119
279256AB1BB322FA00E66B9E /* Command.swift */,
120+
2714C5581BB5403300E0EB6A /* Commands.swift */,
118121
279256B31BB3260D00E66B9E /* Group.swift */,
119122
2768A2251BACC38C00F994EE /* Info.plist */,
120123
);
@@ -245,6 +248,7 @@
245248
files = (
246249
2768A23B1BACC3B600F994EE /* ArgumentParser.swift in Sources */,
247250
2720BDED1BB348BC00C09984 /* ArgumentDescription.swift in Sources */,
251+
2714C5591BB5403400E0EB6A /* Commands.swift in Sources */,
248252
279256AA1BB3226E00E66B9E /* CommandType.swift in Sources */,
249253
279256AC1BB322FA00E66B9E /* Command.swift in Sources */,
250254
279256B61BB32A8E00E66B9E /* ArgumentConvertible.swift in Sources */,

Commander/ArgumentDescription.swift

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -234,72 +234,3 @@ class Help : ErrorType, CustomStringConvertible {
234234
return output.joinWithSeparator("\n")
235235
}
236236
}
237-
238-
239-
public func command<A : ArgumentDescriptor>(descriptor:A, closure:((A.ValueType) -> ())) -> CommandType {
240-
return AnonymousCommand { parser in
241-
if parser.hasOption("help") {
242-
throw Help([BoxedArgumentDescriptor(value: descriptor)])
243-
}
244-
245-
closure(try descriptor.parse(parser))
246-
}
247-
}
248-
249-
public func command<A:ArgumentDescriptor, B:ArgumentDescriptor>(descriptorA:A, _ descriptorB:B, closure:((A.ValueType, B.ValueType) -> ())) -> CommandType {
250-
return AnonymousCommand { parser in
251-
if parser.hasOption("help") {
252-
throw Help([
253-
BoxedArgumentDescriptor(value: descriptorA),
254-
BoxedArgumentDescriptor(value: descriptorB),
255-
])
256-
}
257-
258-
closure(try descriptorA.parse(parser), try descriptorB.parse(parser))
259-
}
260-
}
261-
262-
public func command<A:ArgumentDescriptor, B:ArgumentDescriptor, C:ArgumentDescriptor>(descriptorA:A, _ descriptorB:B, _ descriptorC:C, closure:((A.ValueType, B.ValueType, C.ValueType) -> ())) -> CommandType {
263-
return AnonymousCommand { parser in
264-
if parser.hasOption("help") {
265-
throw Help([
266-
BoxedArgumentDescriptor(value: descriptorA),
267-
BoxedArgumentDescriptor(value: descriptorB),
268-
BoxedArgumentDescriptor(value: descriptorC),
269-
])
270-
}
271-
272-
closure(try descriptorA.parse(parser), try descriptorB.parse(parser), try descriptorC.parse(parser))
273-
}
274-
}
275-
276-
public func command<A:ArgumentDescriptor, B:ArgumentDescriptor, C:ArgumentDescriptor, D:ArgumentDescriptor>(a:A, _ b:B, _ c:C, _ d:D, closure:((A.ValueType, B.ValueType, C.ValueType, D.ValueType) -> ())) -> CommandType {
277-
return AnonymousCommand { parser in
278-
if parser.hasOption("help") {
279-
throw Help([
280-
BoxedArgumentDescriptor(value: a),
281-
BoxedArgumentDescriptor(value: b),
282-
BoxedArgumentDescriptor(value: c),
283-
BoxedArgumentDescriptor(value: d),
284-
])
285-
}
286-
287-
closure(try a.parse(parser), try b.parse(parser), try c.parse(parser), try d.parse(parser))
288-
}
289-
}
290-
291-
public func command<A:ArgumentDescriptor, B:ArgumentDescriptor, C:ArgumentDescriptor, D:ArgumentDescriptor, E:ArgumentDescriptor>(a:A, _ b:B, _ c:C, _ d:D, _ e:E, closure:((A.ValueType, B.ValueType, C.ValueType, D.ValueType, E.ValueType) -> ())) -> CommandType {
292-
return AnonymousCommand { parser in
293-
if parser.hasOption("help") {
294-
throw Help([
295-
BoxedArgumentDescriptor(value: a),
296-
BoxedArgumentDescriptor(value: b),
297-
BoxedArgumentDescriptor(value: c),
298-
BoxedArgumentDescriptor(value: d),
299-
BoxedArgumentDescriptor(value: e),
300-
])
301-
}
302-
303-
closure(try a.parse(parser), try b.parse(parser), try c.parse(parser), try d.parse(parser), try e.parse(parser))
304-
}
305-
}

Commander/Command.swift

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,3 @@ public func command(closure:() -> ()) -> CommandType {
2121
closure()
2222
}
2323
}
24-
25-
/// Create a command which takes one argument using a closure
26-
public func command<A:ArgumentConvertible>(closure:A -> ()) -> CommandType {
27-
return AnonymousCommand { parser in
28-
closure(try A(parser: parser))
29-
}
30-
}
31-
32-
/// Create a command which takes two arguments using a closure
33-
public func command<A:ArgumentConvertible, B:ArgumentConvertible>(closure:(A, B) -> ()) -> CommandType {
34-
return AnonymousCommand { parser in
35-
closure(try A(parser: parser), try B(parser: parser))
36-
}
37-
}
38-
39-
/// Create a command which takes three arguments using a closure
40-
public func command<A:ArgumentConvertible, B:ArgumentConvertible, C:ArgumentConvertible>(closure:(A, B, C) -> ()) -> CommandType {
41-
return AnonymousCommand { parser in
42-
closure(try A(parser: parser), try B(parser: parser), try C(parser: parser))
43-
}
44-
}
45-
46-
/// Create a command which takes four arguments using a closure
47-
public func command<A:ArgumentConvertible, B:ArgumentConvertible, C:ArgumentConvertible, D:ArgumentConvertible>(closure:(A, B, C, D) -> ()) -> CommandType {
48-
return AnonymousCommand { parser in
49-
closure(try A(parser: parser), try B(parser: parser), try C(parser: parser), try D(parser: parser))
50-
}
51-
}
52-
53-
/// Create a command which takes five arguments using a closure
54-
public func command<A:ArgumentConvertible, B:ArgumentConvertible, C:ArgumentConvertible, D:ArgumentConvertible, E:ArgumentConvertible>(closure:(A, B, C, D, E) -> ()) -> CommandType {
55-
return AnonymousCommand { parser in
56-
closure(try A(parser: parser), try B(parser: parser), try C(parser: parser), try D(parser: parser), try E(parser: parser))
57-
}
58-
}

0 commit comments

Comments
 (0)