logbook-cli 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: faa1289d6a90350ba14ebc5385fa377241f7d1b8
4
- data.tar.gz: f3efd0bc44b39eab2e7df5e7375520e53cbabab1
3
+ metadata.gz: 8471149dad881c6f580faebec08b44da16699507
4
+ data.tar.gz: 1951dea527c3070db56d2d3d25b828e81d7ab6b9
5
5
  SHA512:
6
- metadata.gz: 25f46d61436a7ad23fd606edee2e2c758a9dca73926064a33df3798d16fbc535bc40e7813e356bd635e27ef9a8b8a20f0f4ca7002c7f4640b16eded1cd720267
7
- data.tar.gz: 0b9f81ce4b70456f3d64da03fbbb4de5d248484c4e9d114d2118cbddda58a8c4fe0a9075896fd8400c7db275547f317497e4f03e919196713b3b9b60d0efdec6
6
+ metadata.gz: 1b0411a27cc0024f4650c7b9b7cd956601c5b58a18bf73c58a140263d09b7996488a9f47ddaf22a7e847711fddd141a5f7562bd8a0595ff9c42ae08d7d8c8294
7
+ data.tar.gz: 50cc7461cc9437059a31ee43ade706bb6044a7f36ff3f1986fb1cc804d0e35ef80e4061eb2d12f5c4779483016a3dd300b4a1ae0c004beacfa296838d790578e
data/README.md CHANGED
@@ -1,35 +1,57 @@
1
- # Logbook
1
+ # logbook-cli
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/logbook`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ `logbook-cli` is a Ruby gem providing the `logbook` executable which offers
4
+ various commands to process logbook files.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ ## On Logbooks
7
+
8
+ Logbooks are plain text files used to capture thoughts and activities as they
9
+ occur throughout the day without interrupting flow as much as possible.
10
+
11
+ The rather minimalistic syntax is optimized for readability and quick editing
12
+ without the need for anything fancier than a good text editor.
13
+
14
+ To find out more about logbooks and the logbook file format, check out the
15
+ documentation of [the vim plugin](https://github.com/logbooksh/vim-logbook).
6
16
 
7
17
  ## Installation
8
18
 
9
- Add this line to your application's Gemfile:
19
+ `logbook-cli` is packaged as a Ruby gem and requires Ruby 2.4+.
10
20
 
11
- ```ruby
12
- gem 'logbook'
21
+ ```console
22
+ $ gem install logbook-cli
13
23
  ```
14
24
 
15
- And then execute:
25
+ ## Usage
16
26
 
17
- $ bundle
27
+ Once installed, you have access to the `logbook` executable:
18
28
 
19
- Or install it yourself as:
29
+ ```console
30
+ $ logbook
31
+ logbook stats <file>...
32
+ ```
20
33
 
21
- $ gem install logbook
34
+ ### stats
22
35
 
23
- ## Usage
36
+ The `stats` command reads from one or more files and prints out the amount of
37
+ time logged in each file:
24
38
 
25
- TODO: Write usage instructions here
39
+ ```console
40
+ $ logbook stats *.logbook
41
+ 2018-01-18.logbook: 1h47min
42
+ 2018-01-19.logbook: 2h28min
43
+ 2018-01-20.logbook: 2h54min
44
+ 2018-01-21.logbook: 2h48min
45
+ 2018-01-22.logbook: 1h24min
46
+ ```
26
47
 
27
- ## Development
48
+ ## Changelog
28
49
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+ ### 0.1
30
51
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+ * Add `stats` command showing the number of hours logged in a given file
32
53
 
33
- ## Contributing
54
+ ## License
34
55
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/logbook.
56
+ `logbook-cli` is licensed under the Apache License 2.0.
57
+ See [`LICENSE`](LICENSE) for more information.
data/exe/logbook CHANGED
@@ -1,15 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "logbook/cli"
3
+ require "optparse"
4
+ require_relative "../lib/logbook/cli"
4
5
 
5
6
  USAGE = <<~DOC
6
7
  logbook stats <file>...
7
8
  DOC
8
9
 
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{USAGE}"
13
+
14
+ opts.on("--per-task", "Determine duration of each task in the file") do
15
+ options[:per_task] = true
16
+ end
17
+ end.parse!
18
+
9
19
  case ARGV.shift
10
20
  when "stats"
11
21
  paths = ARGV.map { |path| File.expand_path(path) }
12
- Logbook::CLI::App.stats(paths)
22
+ Logbook::CLI::App.stats(paths, options)
13
23
  else
14
24
  puts USAGE
15
25
  end
data/lib/logbook/cli.rb CHANGED
@@ -2,7 +2,7 @@ require "logbook"
2
2
 
3
3
  module Logbook
4
4
  module CLI
5
- require "logbook/cli/app"
6
- require "logbook/cli/version"
5
+ require_relative "cli/app"
6
+ require_relative "cli/version"
7
7
  end
8
8
  end
@@ -1,6 +1,13 @@
1
1
  module Logbook::CLI
2
2
  class App
3
- def self.stats(paths)
3
+ def initialize
4
+ end
5
+
6
+ def self.stats(paths, options = {})
7
+ new.stats(paths, options)
8
+ end
9
+
10
+ def stats(paths, options)
4
11
  return if paths.empty?
5
12
 
6
13
  paths.select { |path| File.file?(path) }.each do |path|
@@ -8,14 +15,37 @@ module Logbook::CLI
8
15
  contents = File.read(path)
9
16
 
10
17
  if page = Logbook::Builder.build(contents)
11
- duration = page.total_duration.minutes.to_i
18
+ total_duration = page.logged_time.minutes.to_i
19
+ next unless total_duration > 0
20
+
21
+ puts "#{name}: #{format_duration(total_duration)}"
12
22
 
13
- hours = duration / 60
14
- minutes = duration % 60
23
+ if options[:per_task]
24
+ page.tasks.each do |_, task|
25
+ task_duration = task.time_logged.minutes.to_i
26
+ next unless task_duration > 0
15
27
 
16
- puts "#{name}: #{hours}h#{minutes}min"
28
+ puts " " * (name.length + 1) + " #{task.title}: #{format_duration(task_duration)}"
29
+ end
30
+ end
17
31
  end
18
32
  end
19
33
  end
34
+
35
+ private
36
+ def format_duration(duration)
37
+ hours = duration / 60
38
+ minutes = duration % 60
39
+
40
+ if duration == 0
41
+ "0"
42
+ elsif minutes == 0
43
+ "#{hours}h"
44
+ elsif hours == 0
45
+ "#{minutes} min"
46
+ else
47
+ "#{hours} h #{minutes} min"
48
+ end
49
+ end
20
50
  end
21
51
  end
@@ -1,5 +1,5 @@
1
1
  module Logbook
2
2
  module CLI
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logbook-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Malkas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler