tlog 0.2.0 → 0.2.1
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.
- checksums.yaml +8 -8
- data/README.md +172 -30
- data/TODO +1 -0
- data/lib/tlog/application.rb +56 -56
- data/lib/tlog/command/active.rb +48 -48
- data/lib/tlog/command/checkout.rb +31 -31
- data/lib/tlog/command/create.rb +40 -40
- data/lib/tlog/command/delete.rb +21 -21
- data/lib/tlog/command/display.rb +195 -148
- data/lib/tlog/command/help.rb +33 -33
- data/lib/tlog/command/owner.rb +25 -25
- data/lib/tlog/command/points.rb +25 -25
- data/lib/tlog/command/pull.rb +18 -18
- data/lib/tlog/command/push.rb +18 -18
- data/lib/tlog/command/start.rb +35 -35
- data/lib/tlog/command/state.rb +25 -25
- data/lib/tlog/command/stop.rb +26 -26
- data/lib/tlog/command.rb +9 -8
- data/lib/tlog/command_suite.rb +29 -29
- data/lib/tlog/entity/active_log.rb +8 -8
- data/lib/tlog/entity/entry.rb +77 -77
- data/lib/tlog/entity/log.rb +161 -161
- data/lib/tlog/error.rb +3 -0
- data/lib/tlog/format/date_time.rb +4 -3
- data/lib/tlog/format/seconds.rb +10 -9
- data/lib/tlog/input.rb +6 -6
- data/lib/tlog/output.rb +28 -28
- data/lib/tlog/storage/disk.rb +326 -326
- data/lib/tlog.rb +1 -1
- metadata +2 -4
- data/lib/tlog/command/init.rb +0 -38
- data/lib/tlog/version.rb +0 -3
data/lib/tlog/command/push.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
|
2
2
|
class Tlog::Command::Push < Tlog::Command
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def name
|
5
|
+
"push"
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def description
|
9
|
+
"pushes your time logs upstream"
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def execute(input, output)
|
13
|
+
push_logs
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def options(parser, options)
|
17
|
+
parser.banner = "usage: tlog push"
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
private
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def push_logs
|
23
|
+
storage.in_branch do |wd|
|
24
|
+
storage.push_logs
|
25
|
+
end
|
26
|
+
end
|
27
27
|
end
|
data/lib/tlog/command/start.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
|
2
2
|
class Tlog::Command::Start < Tlog::Command
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
4
|
+
def name
|
5
|
+
"start"
|
6
|
+
end
|
7
|
+
|
8
|
+
def description
|
9
|
+
"starts a new task for a time log"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(input, output)
|
13
|
+
updated_log = start(input.options[:description])
|
14
|
+
output.line("Started '#{updated_log.name}'")
|
15
|
+
end
|
16
|
+
|
17
|
+
def options(parser, options)
|
18
|
+
parser.banner = "usage: tlog start"
|
19
|
+
|
20
|
+
parser.on("-d", "--description <description>") do |description|
|
21
|
+
options[:description] = description
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def start(entry_description)
|
28
|
+
storage.in_branch do |wd|
|
29
|
+
checked_out_log = storage.checkout_value
|
30
|
+
raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
|
31
|
+
log = storage.require_log(checked_out_log)
|
32
|
+
raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
|
33
|
+
unless storage.start_log(log, entry_description)
|
34
|
+
raise Tlog::Error::CommandInvalid, "Time log '#{checked_out_log}' is already in progress"
|
35
|
+
end
|
36
|
+
log
|
37
|
+
end
|
38
|
+
end
|
39
39
|
end
|
data/lib/tlog/command/state.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
|
2
2
|
class Tlog::Command::State < Tlog::Command
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def name
|
5
|
+
"state"
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def description
|
9
|
+
"changes the state of the checked-out time log"
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def execute(input, output)
|
13
|
+
new_state = input.args[0]
|
14
|
+
updated_log = change_state(new_state)
|
15
|
+
output.line("Changed state of '#{updated_log.name}' to #{new_state}")
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def options(parser, options)
|
19
|
+
parser.banner = "usage: tlog state <new_state>"
|
20
|
+
end
|
21
21
|
|
22
|
-
|
22
|
+
private
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
def change_state(new_state)
|
25
|
+
storage.in_branch do |wd|
|
26
|
+
checked_out_log = storage.checkout_value
|
27
|
+
raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
|
28
|
+
log = storage.require_log(checked_out_log)
|
29
|
+
raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
|
30
|
+
storage.change_log_state(log, new_state)
|
31
|
+
log
|
32
|
+
end
|
33
|
+
end
|
34
34
|
end
|
data/lib/tlog/command/stop.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
class Tlog::Command::Stop < Tlog::Command
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
def name
|
4
|
+
"stop"
|
5
|
+
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def description
|
8
|
+
"ends a task for a time log"
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def execute(input, output)
|
12
|
+
updated_log = stop
|
13
|
+
output.line("Stopped '#{updated_log.name}'")
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def options(parser, options)
|
17
|
+
parser.banner = "usage: tlog stop"
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
private
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
22
|
+
def stop
|
23
|
+
storage.in_branch do |wd|
|
24
|
+
checked_out_log = storage.checkout_value
|
25
|
+
raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
|
26
|
+
log = storage.require_log(checked_out_log)
|
27
|
+
raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
|
28
|
+
unless storage.stop_log(log)
|
29
|
+
raise Tlog::Error::CommandInvalid, "Failed to stop log '#{checked_out_log}': This time log is not in progress"
|
30
|
+
end
|
31
|
+
log
|
32
|
+
end
|
33
|
+
end
|
34
34
|
|
35
35
|
end
|
data/lib/tlog/command.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
|
1
2
|
class Tlog::Command
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
attr_accessor :storage
|
5
|
+
attr_accessor :seconds_format
|
6
|
+
attr_accessor :date_time_format
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def execute(input, output)
|
9
|
+
raise Tlog::Error::NotImplementedError
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def options(parser, options)
|
13
|
+
end
|
13
14
|
|
14
15
|
end
|
data/lib/tlog/command_suite.rb
CHANGED
@@ -2,35 +2,35 @@
|
|
2
2
|
# Simple helper class that handles an array of commands
|
3
3
|
class Tlog::Command_Suite
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
class << self
|
6
|
+
def commands
|
7
|
+
storage = self.working_dir_storage
|
8
|
+
commands = [
|
9
|
+
Tlog::Command::Start.new,
|
10
|
+
Tlog::Command::Stop.new,
|
11
|
+
Tlog::Command::Help.new,
|
12
|
+
Tlog::Command::Active.new,
|
13
|
+
Tlog::Command::Delete.new,
|
14
|
+
Tlog::Command::Display.new,
|
15
|
+
Tlog::Command::Create.new,
|
16
|
+
Tlog::Command::Checkout.new,
|
17
|
+
Tlog::Command::State.new,
|
18
|
+
Tlog::Command::Points.new,
|
19
|
+
Tlog::Command::Owner.new,
|
20
|
+
Tlog::Command::Push.new,
|
21
|
+
Tlog::Command::Pull.new,
|
22
|
+
]
|
23
|
+
commands.each do |command|
|
24
|
+
command.storage = storage
|
25
|
+
command.seconds_format = Tlog::Format::Seconds
|
26
|
+
command.date_time_format = Tlog::Format::DateTime
|
27
|
+
end
|
28
|
+
commands
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def working_dir_storage
|
32
|
+
Tlog::Storage::Disk.new('.')
|
33
|
+
end
|
34
|
+
end
|
35
35
|
|
36
36
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
|
2
2
|
# Helper class for printing out active time logs
|
3
3
|
class Tlog::Entity::Active_Log
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
attr_reader :name
|
5
|
+
attr_accessor :current
|
6
|
+
attr_accessor :checked_out
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def initialize(name)
|
9
|
+
@name = name
|
10
|
+
@current = false
|
11
|
+
@checked_out = false
|
12
|
+
end
|
13
13
|
end
|
data/lib/tlog/entity/entry.rb
CHANGED
@@ -1,82 +1,82 @@
|
|
1
1
|
|
2
2
|
class Tlog::Entity::Entry
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
4
|
+
attr_accessor :hex
|
5
|
+
attr_accessor :path
|
6
|
+
|
7
|
+
def initialize(path, hex)
|
8
|
+
@path = path
|
9
|
+
@hex = hex
|
10
|
+
end
|
11
|
+
|
12
|
+
def length
|
13
|
+
time_difference if time[:start] && time[:end]
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(parent, current)
|
17
|
+
FileUtils.mkdir_p(path)
|
18
|
+
time_log = current[:start_time].to_s + " " + Time.now.to_s
|
19
|
+
write_file(parent_path, parent)
|
20
|
+
write_file(time_path, time_log.strip)
|
21
|
+
write_file(description_path, current[:description])
|
22
|
+
#write_file(owner_path, current[:owner])
|
23
|
+
end
|
24
|
+
|
25
|
+
def parent_hex
|
26
|
+
read_file(parent_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def time
|
30
|
+
time_hash = {}
|
31
|
+
start_time_string = ""
|
32
|
+
end_time_string = ""
|
33
|
+
time_contents = read_file(time_path)
|
34
|
+
return time_hash unless time_contents
|
35
|
+
split_contents = time_contents.split(" ", 6)
|
36
|
+
for i in 0..2
|
37
|
+
start_time_string += split_contents[i] + " "
|
38
|
+
end
|
39
|
+
for i in 3..5
|
40
|
+
end_time_string += split_contents[i] + " "
|
41
|
+
end
|
42
|
+
time_hash[:start] = Time.parse(start_time_string)
|
43
|
+
time_hash[:end] = Time.parse(end_time_string)
|
44
|
+
return time_hash
|
45
|
+
end
|
46
|
+
|
47
|
+
def description
|
48
|
+
read_file(description_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def write_file(path, content)
|
54
|
+
File.open(path, 'w'){ |f| f.write(content)}
|
55
|
+
end
|
56
|
+
|
57
|
+
def read_file(path)
|
58
|
+
if File.exists?(path)
|
59
|
+
contents = File.read(path)
|
60
|
+
contents.strip
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def time_difference
|
65
|
+
time_hash = time
|
66
|
+
difference = time_hash[:end] - time_hash[:start]
|
67
|
+
difference.to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
def parent_path
|
71
|
+
File.join(@path, 'PARENT')
|
72
|
+
end
|
73
|
+
|
74
|
+
def time_path
|
75
|
+
File.join(@path, 'TIME')
|
76
|
+
end
|
77
|
+
|
78
|
+
def description_path
|
79
|
+
File.join(@path, 'DESCRIPTION')
|
80
|
+
end
|
81
81
|
|
82
82
|
end
|