Class: Slimtimercli::CommandLine
- Inherits:
-
Object
- Object
- Slimtimercli::CommandLine
show all
- Includes:
- Helper
- Defined in:
- lib/slimtimercli.rb
Instance Method Summary
collapse
Methods included from Helper
#check_and_create_dir, #config_file, #current_file, #dump_to_file, #load_config, #load_file, #login, #parse, #rm_current, #root, #save_config, #tasks_file
Constructor Details
#initialize(args, output = $stdout) ⇒ CommandLine
Returns a new instance of CommandLine.
24
25
26
27
28
29
30
31
|
# File 'lib/slimtimercli.rb', line 24
def initialize(args, output = $stdout)
@args = args
@out = output
deprecated_calls
@options = parse(args)
end
|
Instance Method Details
#create ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/slimtimercli.rb', line 33
def create
st = login
if st.create_task(@options.task_name)
dump_to_file(st.tasks, tasks_file)
@out.puts "Task #{name} successfully created."
end
end
|
#run ⇒ Object
130
131
132
|
# File 'lib/slimtimercli.rb', line 130
def run
send(@options.run.to_sym)
end
|
#setup ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/slimtimercli.rb', line 50
def setup
config = load_config
@out.puts "Slimtimer Login Credentials\n"
@out.print "E-Mail: "
config["email"] = $stdin.gets.strip
begin
@out.print "Password: "
system("stty -echo")
config["password"] = $stdin.gets.strip
ensure
system("stty echo")
end
@out.print "\nAPI Key: "
config["api_key"] = $stdin.gets.strip
save_config(config)
end
|
#start ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/slimtimercli.rb', line 72
def start
if File.exists?(current_file)
@out.puts "Need to stop the other task first"
return false
end
info = {"task" => @options.task_name,
"start_time" => Time.now}
t = load_tasks.find {|t| t.name == info["task"]}
unless t
@out.puts "Task not found in list. Reload List?"
return false
end
dump_to_file(info, current_file)
return true
end
|
#stop ⇒ Object
Also known as:
end
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/slimtimercli.rb', line 92
def stop
if @options.force
rm_current
@out.puts "Forced ending of task, no entry to slimtimer.com written"
return true
end
begin
info = load_file(current_file)
rescue
puts "You must start a task before you finish it"
return false
end
t = load_tasks.find {|t| t.name == info["task"]}
unless t
@out.puts "Task not found in list. Reload List?"
return false
end
st = login
result = st.create_time_entry(t, info["start_time"],
(Time.now - info["start_time"]).to_i)
if result
rm_current
@out.puts "Wrote new Entry for #{t.name}, duration #{result["duration_in_seconds"] / 60}m"
return true
else
@out.puts "Coult not write new entry, please try again"
return false
end
end
|
#tasks(show = true) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/slimtimercli.rb', line 41
def tasks(show = true)
tasks = load_tasks
return tasks unless show
tasks.each do |t|
@out.puts t.name
end
end
|