chronolog 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2121db8e20b57a6cd648cf542b0d83daabf643122a535fc4eaf4d3a3c5f14fc9
4
- data.tar.gz: 0e266057d3ef6ac6efe377b30669d15819d6c6dee267753de280c319d8e2a920
3
+ metadata.gz: b1cfd1f135d109930f56b6242aa87bdf6d04a6e082a68638a134fc8596c43833
4
+ data.tar.gz: fb105b43a137eec656b65cd7520108b51bfde22fcbff77b7e9a6aecd75548f49
5
5
  SHA512:
6
- metadata.gz: 5d6688dc5c6f56dc2afb7abb6d83fa248c350688e9e3a512db73ae46c7572cdfa1bdd2ad82d67c7d2efcc29ee66fa41b560352ee3db7add105faab5bc572a2af
7
- data.tar.gz: 8607f17597c5e907575e08d134451f77c092f3a8e5f580c1bfeb40c9d6f60bb776c990b3722f2799d0d894b49d2e8fca1c945e7bfc5515df083c05b73b9ea9ea
6
+ metadata.gz: 87942460f5e3be3ec80321a9a31f51dd5de719cfc8535f5fef33ae980c28f8dcd2fe07a24165d4f84cd63185acdb53d6620457596978472ab41669b80a6ff05e
7
+ data.tar.gz: 27a2d89476f0a8749bd2f13deed3b4ab254600adaa6ee189df6618571b747af3f3717bb0f6b99bcf8032e4085817745def9403ca9962c8afdf05caa38587e7dc
data/README.md CHANGED
@@ -3,9 +3,10 @@ Chronolog
3
3
 
4
4
  [![Gem](https://img.shields.io/gem/v/chronolog.svg)](https://rubygems.org/gems/chronolog)
5
5
 
6
+ Chronolog is a CLI for logging time in plain text files.
6
7
 
7
- Install
8
- -------
8
+ Installation
9
+ ------------
9
10
 
10
11
  Get it from RubyGems:
11
12
 
@@ -19,6 +20,61 @@ Or build it from GitHub:
19
20
  $ gem install chronolog-*.gem
20
21
 
21
22
 
23
+ Usage
24
+ -----
25
+
26
+ Run Chronolog in interactive mode:
27
+
28
+ $ chronolog work.log
29
+ > started last monday at 09:30
30
+ Started session at 2018-09-24 09:30:00 +0200
31
+ > stopped last monday at 18:00
32
+ Stopped session at 2018-09-24 18:00:00 +0200
33
+ > started yesterday at 10:00
34
+ Started session at 2018-09-29 10:00:00 +0200
35
+ > stopped yesterday at 19:30
36
+ Stopped session at 2018-09-29 19:30:00 +0200
37
+ > print last monday
38
+ Time logged for 2018-09-24
39
+ Year: 18.00 hours
40
+ Month: 18.00 hours
41
+ Day: 8.50 hours
42
+ > print yesterday
43
+ Time logged for 2018-09-27
44
+ Year: 18.00 hours
45
+ Month: 18.00 hours
46
+ Day: 9.50 hours
47
+ > quit
48
+
49
+ Or run chronolog one command at a time:
50
+
51
+ $ chronolog work.log started 30 minutes ago
52
+ Started session at 2018-09-28 10:00:00 +0200
53
+
54
+ $ chronolog work.log print
55
+ Time logged for 2018-09-28
56
+ Year: 18.30 hours
57
+ Month: 18.30 hours
58
+ Day: 0.30 hours
59
+ Session: 0.30 hours
60
+
61
+ $ chronolog work.log stop
62
+ Stopped session at 2018-09-28 10:30:00 +0200
63
+
64
+ Everything is saved in plain text so you can also edit the file directly:
65
+
66
+ $ date +'started at %s # plain text <3' >> work.log
67
+
68
+ $ cat work.log
69
+ started at 1537774200
70
+ stopped at 1537804800
71
+ started at 1538035200
72
+ stopped at 1538069400
73
+ started at 1538121600
74
+ stopped at 1538123400
75
+ started at 1538123410 # plain text <3
76
+
77
+
22
78
  License
23
79
  -------
24
80
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  require "chronolog"
4
4
 
5
- path = ARGV.pop
5
+ path = ARGV.shift
6
6
  cmd = ARGV.join(" ")
7
7
  Chronolog::CLI.new(path).run(cmd)
@@ -3,7 +3,7 @@ require "readline"
3
3
  module Chronolog
4
4
  class CLI
5
5
  CLI_CMDS = %w[quit help].freeze
6
- LIB_CMDS = %w[print start stop].freeze
6
+ LIB_CMDS = %w[print start started stop stopped].freeze
7
7
  CMDS = (CLI_CMDS + LIB_CMDS).sort.freeze
8
8
 
9
9
  def initialize(path)
@@ -29,21 +29,41 @@ module Chronolog
29
29
  protected
30
30
 
31
31
  def exec(cmd)
32
- args = cmd.split
33
32
  exit if cmd =~ /^q/
34
- return @chronolog.send(args.shift, *args) if LIB_CMDS.include?(args[0])
35
- usage
33
+ args = cmd.split
34
+ name = args.shift
35
+ return usage unless LIB_CMDS.include?(name)
36
+ @chronolog.send(name, **parse(args))
36
37
  rescue StandardError => e
37
- puts "Error: #{e.message}"
38
+ print_error(e.message)
39
+ end
40
+
41
+ def parse(args)
42
+ key = :time
43
+ args.each_with_object({}) do |arg, opts|
44
+ case arg
45
+ when "at", "on", "for"
46
+ key = :time
47
+ when "in"
48
+ key = :unit
49
+ else
50
+ opts[key] = "#{opts[key]} #{arg}".lstrip if key
51
+ end
52
+ end
38
53
  end
39
54
 
40
55
  def usage
41
56
  unless @interactive
42
- puts "Usage: chronolog [command] <file.log>"
57
+ puts "Usage: chronolog <file.log> [command]"
43
58
  puts
44
59
  end
45
60
  commands = (@interactive ? CMDS : LIB_CMDS).join("', '")
46
61
  puts "Available commands: '#{commands}'"
47
62
  end
63
+
64
+ def print_error(text)
65
+ error = Rainbow("Error:").red
66
+ puts "#{error} #{text}"
67
+ end
48
68
  end
49
69
  end
@@ -1,4 +1,6 @@
1
1
  require "csv"
2
+ require "chronic"
3
+ require "rainbow"
2
4
 
3
5
  module Chronolog
4
6
  class Engine
@@ -9,32 +11,45 @@ module Chronolog
9
11
  read_csv
10
12
  end
11
13
 
12
- def start
14
+ def start(time: "now")
13
15
  raise "Received 'start' after 'start'" unless @started_at.nil?
14
- @started_at = Time.now
16
+ @started_at = Chronic.parse(time)
15
17
  @csv << ["started", "at", @started_at.to_i]
18
+ print_header(format("Started session at %s", @started_at))
16
19
  end
17
20
 
18
- def stop
21
+ def stop(time: "now")
19
22
  raise "Received 'stop' before 'start'" if @started_at.nil?
20
- @stopped_at = Time.now
23
+ @stopped_at = Chronic.parse(time)
21
24
  @csv << ["stopped", "at", @stopped_at.to_i]
22
25
  update_variables
23
26
  @started_at = nil
27
+ print_header(format("Stopped session at %s", @stopped_at))
24
28
  end
25
29
 
26
- def print(unit = "hours")
27
- started_at = @started_at || Time.now
28
- stopped_at = Time.now
30
+ def print(unit: "hours", time: "now")
31
+ stopped_at = Chronic.parse(time)
32
+ started_at = @started_at || stopped_at
29
33
  current = stopped_at - started_at
34
+ print_header(format("Time logged for %s", stopped_at.strftime("%F")))
30
35
  %w[year month day session].each do |period|
36
+ next if period == "session" && time != "now"
31
37
  duration = (current + previous(period, started_at)) / unit_length(unit)
32
- puts format("This %- 10s % 7.2f %s", "#{period}:", duration, unit)
38
+ left = Rainbow(format("%- 10s", "#{period.capitalize}:"))
39
+ right = Rainbow(format("% 9.2f %s", duration, unit)).cyan
40
+ puts "#{left} #{right}"
33
41
  end
34
42
  end
35
43
 
44
+ alias started start
45
+ alias stopped stop
46
+
36
47
  protected
37
48
 
49
+ def print_header(text)
50
+ puts Rainbow(text).yellow
51
+ end
52
+
38
53
  def setup_variables
39
54
  @years = Hash.new(0)
40
55
  @months = Hash.new(0)
@@ -1,3 +1,3 @@
1
1
  module Chronolog
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronolog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Ollivier
@@ -9,7 +9,47 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-09-30 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chronic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.10.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.10.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rainbow
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.0.0
13
53
  description:
14
54
  email: v@vinc.cc
15
55
  executables:
@@ -47,5 +87,5 @@ rubyforge_project:
47
87
  rubygems_version: 2.7.6
48
88
  signing_key:
49
89
  specification_version: 4
50
- summary: Log elapsed time
90
+ summary: Chronolog is a CLI for logging time in plain text files
51
91
  test_files: []