slimtimercli 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +1 -0
- data/lib/slimtimercli/helper.rb +168 -0
- data/lib/slimtimercli/version.rb +1 -1
- metadata +2 -1
data/Manifest.txt
CHANGED
@@ -0,0 +1,168 @@
|
|
1
|
+
module Slimtimercli
|
2
|
+
module Helper
|
3
|
+
def login
|
4
|
+
config = Helper::load_config
|
5
|
+
st = SlimTimer.new(config["email"], config["password"],
|
6
|
+
config["api_key"])
|
7
|
+
st.login
|
8
|
+
|
9
|
+
st
|
10
|
+
end
|
11
|
+
|
12
|
+
def root
|
13
|
+
@root ||= if ENV.key?("XDG_CONFIG_HOME") and File.exists?( ENV['XDG_CONFIG_HOME'] )
|
14
|
+
File.join(ENV['XDG_CONFIG_HOME'], "slimtimer")
|
15
|
+
else
|
16
|
+
File.join(ENV["HOME"], ".slimtimer")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def config_file
|
21
|
+
File.join(root, "config.yml")
|
22
|
+
end
|
23
|
+
|
24
|
+
def tasks_file
|
25
|
+
File.join(root, "tasks.yml")
|
26
|
+
end
|
27
|
+
|
28
|
+
def current_file
|
29
|
+
File.join(root, "current.yml")
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_and_create_dir
|
33
|
+
raise "Home DIR not set!" unless ENV["HOME"]
|
34
|
+
|
35
|
+
unless File.directory?(root)
|
36
|
+
FileUtils.mkdir(root)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_config
|
41
|
+
check_and_create_dir
|
42
|
+
|
43
|
+
unless File.exists?(config_file)
|
44
|
+
File.open( config_file, 'w' ) do |out|
|
45
|
+
YAML.dump({}, out )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
load_file(config_file)
|
49
|
+
end
|
50
|
+
|
51
|
+
def save_config(config)
|
52
|
+
dump_to_file(config, config_file)
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_file(file)
|
56
|
+
File.open( file ) { |yf| YAML::load( yf ) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def dump_to_file(object, file)
|
60
|
+
check_and_create_dir
|
61
|
+
File.open( file, 'w' ) do |out|
|
62
|
+
YAML.dump(object, out )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def rm_current
|
67
|
+
FileUtils.rm(current_file) if
|
68
|
+
File.exists?(current_file)
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse(args)
|
72
|
+
|
73
|
+
if !args || args.empty?
|
74
|
+
warn "Need to specify arguments, run slimtimer -h for help"
|
75
|
+
exit 2
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
options = OpenStruct.new
|
80
|
+
options.force = false
|
81
|
+
|
82
|
+
opts = OptionParser.new do |opts|
|
83
|
+
|
84
|
+
opts.banner = "Usage: slimtimer [options]"
|
85
|
+
|
86
|
+
opts.on("-s TASK", "--start TASK",
|
87
|
+
"Start a TASK given by the task name") do |t|
|
88
|
+
|
89
|
+
options.run = "start"
|
90
|
+
options.task_name = t
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.on("-c TASK", "--create TASK",
|
94
|
+
"Create a ne task by the given name") do |t|
|
95
|
+
options.run = "create"
|
96
|
+
options.task_name = t
|
97
|
+
end
|
98
|
+
|
99
|
+
opts.on("-e", "--end" ,"Stops time recording for the given task") do
|
100
|
+
options.run = "stop"
|
101
|
+
end
|
102
|
+
|
103
|
+
opts.on("-t", "--tasks", "Prints all available tasks") do
|
104
|
+
options.run = "tasks"
|
105
|
+
end
|
106
|
+
|
107
|
+
opts.on("-f", "--force", "Force deletion of tasks") do
|
108
|
+
options.force = true
|
109
|
+
end
|
110
|
+
|
111
|
+
opts.on("--setup", "Setup your account") do
|
112
|
+
options.run = "setup"
|
113
|
+
end
|
114
|
+
|
115
|
+
opts.on_tail("-h", "Shows this note") do
|
116
|
+
puts opts
|
117
|
+
exit
|
118
|
+
end
|
119
|
+
|
120
|
+
opts.on("--help", "Show verbose help") do
|
121
|
+
@out.puts <<-HELP
|
122
|
+
SlimTimer is a tool to record your time spend on a
|
123
|
+
task. SlimTimer CLI allows you to controll your
|
124
|
+
SlimTimer directly from where you spend most of your
|
125
|
+
time - on the command line. To use SlimTimer proceed
|
126
|
+
with the following steps:
|
127
|
+
|
128
|
+
The first time you need to setup SlimTimer CLI with
|
129
|
+
|
130
|
+
slimtimer setup
|
131
|
+
|
132
|
+
Now it will ask for your email and password and API key
|
133
|
+
to use with your account. These information will be stored
|
134
|
+
in #{config_file}
|
135
|
+
|
136
|
+
To create a task run
|
137
|
+
|
138
|
+
slimtimer create_task my_shiny_task
|
139
|
+
|
140
|
+
To spend some time on the task you have to make the timer run
|
141
|
+
|
142
|
+
slimtimer start my_shiny_task
|
143
|
+
|
144
|
+
When you finished working on a task, you can call
|
145
|
+
|
146
|
+
slimtimer end
|
147
|
+
|
148
|
+
This will write the time spend back to SlimTimer.com.
|
149
|
+
Finally you can run
|
150
|
+
|
151
|
+
slimtimer tasks
|
152
|
+
|
153
|
+
To show all your tasks available.
|
154
|
+
HELP
|
155
|
+
exit
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
begin
|
160
|
+
opts.parse!(args)
|
161
|
+
rescue
|
162
|
+
puts $!.message
|
163
|
+
exit
|
164
|
+
end
|
165
|
+
options
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/lib/slimtimercli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slimtimercli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Grund
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/slimtimercli.rb
|
67
67
|
- lib/slimtimercli/entities.rb
|
68
68
|
- lib/slimtimercli/slim_timer.rb
|
69
|
+
- lib/slimtimercli/helper.rb
|
69
70
|
- lib/slimtimercli/version.rb
|
70
71
|
- log/debug.log
|
71
72
|
- setup.rb
|