logbook-cli 0.1.0 → 0.1.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 +4 -4
- data/README.md +39 -17
- data/exe/logbook +12 -2
- data/lib/logbook/cli.rb +2 -2
- data/lib/logbook/cli/app.rb +35 -5
- data/lib/logbook/cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8471149dad881c6f580faebec08b44da16699507
|
4
|
+
data.tar.gz: 1951dea527c3070db56d2d3d25b828e81d7ab6b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b0411a27cc0024f4650c7b9b7cd956601c5b58a18bf73c58a140263d09b7996488a9f47ddaf22a7e847711fddd141a5f7562bd8a0595ff9c42ae08d7d8c8294
|
7
|
+
data.tar.gz: 50cc7461cc9437059a31ee43ade706bb6044a7f36ff3f1986fb1cc804d0e35ef80e4061eb2d12f5c4779483016a3dd300b4a1ae0c004beacfa296838d790578e
|
data/README.md
CHANGED
@@ -1,35 +1,57 @@
|
|
1
|
-
#
|
1
|
+
# logbook-cli
|
2
2
|
|
3
|
-
|
3
|
+
`logbook-cli` is a Ruby gem providing the `logbook` executable which offers
|
4
|
+
various commands to process logbook files.
|
4
5
|
|
5
|
-
|
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
|
-
|
19
|
+
`logbook-cli` is packaged as a Ruby gem and requires Ruby 2.4+.
|
10
20
|
|
11
|
-
```
|
12
|
-
gem
|
21
|
+
```console
|
22
|
+
$ gem install logbook-cli
|
13
23
|
```
|
14
24
|
|
15
|
-
|
25
|
+
## Usage
|
16
26
|
|
17
|
-
|
27
|
+
Once installed, you have access to the `logbook` executable:
|
18
28
|
|
19
|
-
|
29
|
+
```console
|
30
|
+
$ logbook
|
31
|
+
logbook stats <file>...
|
32
|
+
```
|
20
33
|
|
21
|
-
|
34
|
+
### stats
|
22
35
|
|
23
|
-
|
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
|
-
|
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
|
-
##
|
48
|
+
## Changelog
|
28
49
|
|
29
|
-
|
50
|
+
### 0.1
|
30
51
|
|
31
|
-
|
52
|
+
* Add `stats` command showing the number of hours logged in a given file
|
32
53
|
|
33
|
-
##
|
54
|
+
## License
|
34
55
|
|
35
|
-
|
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 "
|
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
data/lib/logbook/cli/app.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module Logbook::CLI
|
2
2
|
class App
|
3
|
-
def
|
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
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
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
|
data/lib/logbook/cli/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|