Last active
February 11, 2019 17:22
-
-
Save calebkleveter/9f269d8f5323f2a4679be53e57939c9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeCommand: Command { | |
struct Arguments: CommandArguments { | |
let string = Argument<String>(name: "string", help: "The string to print to srdout") | |
let count = Argument<Int>(name: "count", help: "The number of times to output the string") | |
} | |
struct Options: CommandOptions { | |
let verbose = Option<Bool>(name: "verbose", short: "v", help: "List each output on its own line") | |
} | |
func run(on context: CommandContext<SomeCommand>)throws -> Future<Void> { | |
let name = try context.argument(\.name) | |
let count = try context.argument(\.count) | |
if try context.options(\.verbose) { | |
(1...count).forEach { _ in print(name) } | |
} else { | |
print(String(repeating: name, count: count)) | |
} | |
return Future(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment