Class: Traker::CLI
- Inherits:
-
Object
- Object
- Traker::CLI
- Defined in:
- lib/traker/cli.rb
Overview
Traker’s CLI interfase
Constant Summary collapse
- SUBTEXT =
" Possible commands are:\n list: lists rake tasks known to Traker (shows list of pending tasks by default)\n See 'traker COMMAND --help' for more information on a specific command.\n"- SUBCOMMANDS =
{ list: 'list' }.freeze
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/traker/cli.rb', line 17 def initialize @main = OptionParser.new do |opts| opts. = 'Usage: traker [options] [subcommand] [options]' opts.on('-v', '--version', 'Show version') opts.separator '' opts.separator SUBTEXT end @subcommands = { SUBCOMMANDS[:list] => OptionParser.new do |opts| opts. = 'Usage: list [options]' opts.on('-a', '--all', 'list all tasks') end } end |
Instance Method Details
#run(argv) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/traker/cli.rb', line 33 def run(argv) = {} @main.order!(argv, into: ) if [:version] puts Traker::VERSION return end subcommand = argv.shift = {} @subcommands[subcommand]&.order!(argv, into: ) service = Traker::Service.new case subcommand when SUBCOMMANDS[:list] if [:all] print service.tasks.join("\n") else print service.pending_tasks.join("\n") end end end |