Class: Hiptask::CLI
- Inherits:
-
Thor
- Object
- Thor
- Hiptask::CLI
- Defined in:
- lib/hiptask/cli.rb
Constant Summary collapse
- @@config =
{}
- @@config_file =
ENV['HOME'] + '/.hiptask/config.yml'
- @@tasks_file =
ENV['HOME'] + '/.hiptask/tasks.txt'
- @@message =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #add(content) ⇒ Object
- #config(action = nil, key = nil, value = nil) ⇒ Object
- #delete(id) ⇒ Object
- #do(id) ⇒ Object
- #list ⇒ Object
- #undo(id) ⇒ Object
- #update(id, content) ⇒ Object
- #version ⇒ Object
Class Method Details
.start(argv) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hiptask/cli.rb', line 19 def self.start(argv) # Config config_dir = File.dirname(@@config_file) Dir.mkdir(config_dir) unless Dir.exists? config_dir unless File.exists? @@config_file file = File.open(@@config_file, "w+") { |file | file.puts "tasks_file: " + @@tasks_file } end @@config = YAML::load_file(@@config_file) @@tasks_file = @@config['tasks_file'] if @@config['tasks_file'] # Environment @@list = List.new(@@tasks_file) super argv end |
Instance Method Details
#add(content) ⇒ Object
97 98 99 100 101 |
# File 'lib/hiptask/cli.rb', line 97 def add(content) @@list.add(content) = "Task #{@@list.items.length - 1} was created" list end |
#config(action = nil, key = nil, value = nil) ⇒ Object
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 |
# File 'lib/hiptask/cli.rb', line 41 def config(action=nil, key=nil, value=nil) case action when 'get' puts @@config[key] when 'set' if value @@config[key] = value puts key + ' = ' + value.to_s else @@config.delete(key) unless value puts "deleted " + key end File.open(@@config_file, "w") { |file| YAML.dump(@@config, file) } when 'delete' puts "deleted " + key @@config.delete(key) File.open(@@config_file, "w") { |file| YAML.dump(@@config, file) } else puts @@config end end |
#delete(id) ⇒ Object
129 130 131 132 133 |
# File 'lib/hiptask/cli.rb', line 129 def delete(id) @@list.delete(id) = "Task #{id} deleted" list end |
#do(id) ⇒ Object
105 106 107 108 109 |
# File 'lib/hiptask/cli.rb', line 105 def do(id) @@list.do(id) = "Task #{id} is now marked as complete" list end |
#list ⇒ Object
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 |
# File 'lib/hiptask/cli.rb', line 69 def list() puts " " puts " \033[33m[ \033[1m#{@@message}\033[0;33m ]\033[0m\n\n" if puts " \033[32;1m#{@@list.items.length} Items\033[0m" puts " " if @@list.items.length > 0 @@list.items.each_with_index { |item, index| index = index + 1 print " \033[33m#{index.to_s.ljust(2)}\033[0m" if item.start_with? ">" print " [x] " puts "#{item[1, item.length - 1]}" else print " [ ] " puts "#{item}" end } else puts " \033[33mAdd a new task with: \033[1mhiptask add \"Get milk\"\033[0m" end puts " " end |
#undo(id) ⇒ Object
113 114 115 116 117 |
# File 'lib/hiptask/cli.rb', line 113 def undo(id) @@list.undo(id) = "Task #{id} is now marked as incomplete" list end |
#update(id, content) ⇒ Object
121 122 123 124 125 |
# File 'lib/hiptask/cli.rb', line 121 def update(id, content) @@list.update(id, content) = "Task #{id} updated" list end |
#version ⇒ Object
137 138 139 |
# File 'lib/hiptask/cli.rb', line 137 def version puts "Hiptask #{Hiptask::VERSION}" end |