Skip to content

Instantly share code, notes, and snippets.

@calebkleveter
Last active February 11, 2019 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebkleveter/9f269d8f5323f2a4679be53e57939c9e to your computer and use it in GitHub Desktop.
Save calebkleveter/9f269d8f5323f2a4679be53e57939c9e to your computer and use it in GitHub Desktop.
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