daygram 0.1.1 → 0.1.5
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 +6 -2
- data/lib/daygram/cli.rb +46 -54
- data/lib/daygram/cli_helpers.rb +5 -0
- data/lib/daygram/database.rb +19 -1
- data/lib/daygram/database/dataset.rb +12 -0
- data/lib/daygram/identity.rb +1 -1
- metadata +2 -2
- data/lib/daygram/cli/read.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97ff052bcb2a09641871113301f09899f304b667
|
4
|
+
data.tar.gz: d994d82e9b8e27060d12ec3749f30683e3fa53fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb220d5df556b5738e1315499769ba06283df186a867551d1a8abccf58e1f8db42515be1060e90c04d78c661c99b90aea5aeae39ff2e30df2e61c25c43799173
|
7
|
+
data.tar.gz: af86c49a18f6955b0f708eb7dbb854fe5e018fc85284bf37f7f06b6f46d92af3460870dba3c86c5a21f66735b4dd1a1ef4eae2e7b382251fefc94d9063cd5ab9
|
data/README.md
CHANGED
@@ -55,9 +55,13 @@ To print the latest entry:
|
|
55
55
|
|
56
56
|
daygram read latest
|
57
57
|
|
58
|
-
To print the last
|
58
|
+
To print the last 3 entries:
|
59
59
|
|
60
|
-
daygram read last
|
60
|
+
daygram read last 3
|
61
|
+
|
62
|
+
To print the entry for a particular date:
|
63
|
+
|
64
|
+
daygram read day 2016-11-15
|
61
65
|
|
62
66
|
To print the entries as JSON, Ruby Hash, or a table:
|
63
67
|
|
data/lib/daygram/cli.rb
CHANGED
@@ -8,8 +8,49 @@ require "runcom"
|
|
8
8
|
require "json"
|
9
9
|
require "pp"
|
10
10
|
require "terminal-table"
|
11
|
+
require "daygram/cli_helpers"
|
11
12
|
|
12
13
|
module Daygram
|
14
|
+
class Read < Thor
|
15
|
+
include Thor::Actions
|
16
|
+
include ThorPlus::Actions
|
17
|
+
include Daygram::CLIHelpers
|
18
|
+
|
19
|
+
def initialize args = [], options = {}, config = {}
|
20
|
+
super args, options, config
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
Runcom::Configuration.new file_name: Daygram::Identity.file_name
|
25
|
+
end
|
26
|
+
|
27
|
+
class_option :format, :type => :string, :aliases => ['-f']
|
28
|
+
|
29
|
+
desc "all", %(Read all entries.)
|
30
|
+
def all
|
31
|
+
db = Daygram::Database.new(options, self.class.configuration)
|
32
|
+
say db.all.format_output(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "latest", %(Read latest entry.)
|
36
|
+
def latest
|
37
|
+
db = Daygram::Database.new(options, self.class.configuration)
|
38
|
+
say db.latest.format_output(options)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "last N", %(Read last N entries.)
|
42
|
+
def last n=5
|
43
|
+
db = Daygram::Database.new(options, self.class.configuration)
|
44
|
+
say db.last(n).format_output(options)
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "day YYYY-MM-DD", %(Read YYYY-MM-DD entry.)
|
48
|
+
def day date
|
49
|
+
db = Daygram::Database.new(options, self.class.configuration)
|
50
|
+
say db.day(date).format_output(options)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
13
54
|
# The Command Line Interface (CLI) for the gem.
|
14
55
|
class CLI < Thor
|
15
56
|
include Thor::Actions
|
@@ -26,9 +67,8 @@ module Daygram
|
|
26
67
|
end
|
27
68
|
|
28
69
|
class_option :database, :type => :string, :aliases => ['-d', '-db']
|
29
|
-
class_option :format, :type => :string, :aliases => ['-f']
|
30
70
|
|
31
|
-
desc "
|
71
|
+
desc "config", %(Manage gem configuration ("#{configuration.computed_path}").)
|
32
72
|
map %w[c config -c --config] => :config
|
33
73
|
method_option :edit,
|
34
74
|
aliases: "-e",
|
@@ -52,67 +92,19 @@ module Daygram
|
|
52
92
|
end
|
53
93
|
end
|
54
94
|
|
55
|
-
desc "
|
95
|
+
desc "version", "Show gem version."
|
56
96
|
map %w[v version -v --version] => :version
|
57
97
|
def version
|
58
98
|
say Identity.version_label
|
59
99
|
end
|
60
100
|
|
61
|
-
desc "
|
101
|
+
desc "help COMMAND", "Show this message or get help for a command."
|
62
102
|
map %w[h help -h --help] => :help
|
63
103
|
def help task = nil
|
64
104
|
say and super
|
65
105
|
end
|
66
106
|
|
67
|
-
desc "
|
68
|
-
|
69
|
-
method_option :all,
|
70
|
-
aliases: "a",
|
71
|
-
desc: "Read all entries.",
|
72
|
-
type: :boolean, default: false
|
73
|
-
method_option :latest,
|
74
|
-
desc: "Read latest entry.",
|
75
|
-
type: :boolean, default: false
|
76
|
-
method_option :last,
|
77
|
-
desc: "Read last N entries.",
|
78
|
-
type: :boolean, default: true
|
79
|
-
|
80
|
-
def read task = nil
|
81
|
-
config = self.class.configuration
|
82
|
-
|
83
|
-
if options[:database]
|
84
|
-
db_path = options[:database]
|
85
|
-
elsif config.to_h["database"]
|
86
|
-
db_path = config.to_h["database"]
|
87
|
-
else
|
88
|
-
say "Must specify the database location"
|
89
|
-
return
|
90
|
-
end
|
91
|
-
|
92
|
-
unless File.exists? db_path
|
93
|
-
say "Specified DB does not exist: #{db_path}"
|
94
|
-
return
|
95
|
-
end
|
96
|
-
|
97
|
-
db = Daygram::Database.new(db_path)
|
98
|
-
|
99
|
-
if task == 'all'
|
100
|
-
output = db.all
|
101
|
-
elsif task == 'last'
|
102
|
-
output = db.last(5)
|
103
|
-
elsif task == 'latest'
|
104
|
-
output = db.latest
|
105
|
-
end
|
106
|
-
|
107
|
-
if options[:format] == 'hash'
|
108
|
-
pp output.to_hash
|
109
|
-
elsif options[:format] == 'json'
|
110
|
-
pp output.to_json
|
111
|
-
elsif options[:format] == 'table'
|
112
|
-
say Terminal::Table.new :title => "Daygram Diary", :headings => output.diary_fields, :rows => output.to_array
|
113
|
-
else
|
114
|
-
say output.to_s
|
115
|
-
end
|
116
|
-
end
|
107
|
+
desc "read", %(Read the Daygram journal.)
|
108
|
+
subcommand "read", Read
|
117
109
|
end
|
118
110
|
end
|
data/lib/daygram/database.rb
CHANGED
@@ -3,7 +3,21 @@ require "daygram/database/dataset"
|
|
3
3
|
|
4
4
|
module Daygram
|
5
5
|
class Database
|
6
|
-
def initialize
|
6
|
+
def initialize options = {}, config = {}
|
7
|
+
@options = options
|
8
|
+
@config = config
|
9
|
+
if @options[:database]
|
10
|
+
path = @options[:database]
|
11
|
+
elsif config.to_h["database"]
|
12
|
+
path = @config.to_h["database"]
|
13
|
+
else
|
14
|
+
raise "Must specify the database location"
|
15
|
+
end
|
16
|
+
|
17
|
+
unless File.exists? path
|
18
|
+
raise "Specified DB does not exist: #{path}"
|
19
|
+
end
|
20
|
+
|
7
21
|
@DB = Sequel.sqlite(path)
|
8
22
|
end
|
9
23
|
|
@@ -18,5 +32,9 @@ module Daygram
|
|
18
32
|
def all
|
19
33
|
Dataset.new(@DB[:diary].order(:date))
|
20
34
|
end
|
35
|
+
|
36
|
+
def day date
|
37
|
+
Dataset.new(@DB[:diary].where("date == '#{date}'"))
|
38
|
+
end
|
21
39
|
end
|
22
40
|
end
|
@@ -45,6 +45,18 @@ module Daygram
|
|
45
45
|
def to_json
|
46
46
|
to_hash.to_json
|
47
47
|
end
|
48
|
+
|
49
|
+
def format_output options
|
50
|
+
if options[:format] == 'hash'
|
51
|
+
self.to_hash
|
52
|
+
elsif options[:format] == 'json'
|
53
|
+
self.to_json
|
54
|
+
elsif options[:format] == 'table'
|
55
|
+
Terminal::Table.new :title => "Daygram Diary", :headings => diary_fields, :rows => self.to_array
|
56
|
+
else
|
57
|
+
self.to_s
|
58
|
+
end
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
end
|
data/lib/daygram/identity.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daygram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon High
|
@@ -249,7 +249,7 @@ files:
|
|
249
249
|
- bin/daygram
|
250
250
|
- lib/daygram.rb
|
251
251
|
- lib/daygram/cli.rb
|
252
|
-
- lib/daygram/
|
252
|
+
- lib/daygram/cli_helpers.rb
|
253
253
|
- lib/daygram/database.rb
|
254
254
|
- lib/daygram/database/dataset.rb
|
255
255
|
- lib/daygram/identity.rb
|
data/lib/daygram/cli/read.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Daygram
|
2
|
-
module CLISubcommands
|
3
|
-
class Read < Thor
|
4
|
-
map %w[r read] => :read
|
5
|
-
method_option :all,
|
6
|
-
aliases: "a",
|
7
|
-
desc: "Read all entries.",
|
8
|
-
type: :boolean, default: false
|
9
|
-
method_option :latest,
|
10
|
-
desc: "Read latest entry.",
|
11
|
-
type: :boolean, default: false
|
12
|
-
method_option :last,
|
13
|
-
desc: "Read last N entries.",
|
14
|
-
type: :numeric, default: 5
|
15
|
-
argument :number, :type => :numeric, :desc => "The number to start counting"
|
16
|
-
desc "read", %(Read the Daygram journal.)
|
17
|
-
def read task = nil
|
18
|
-
config = self.class.configuration
|
19
|
-
|
20
|
-
if options[:database]
|
21
|
-
db_path = options[:database]
|
22
|
-
elsif config.to_h["database"]
|
23
|
-
db_path = config.to_h["database"]
|
24
|
-
else
|
25
|
-
say "Must specify the database location"
|
26
|
-
return
|
27
|
-
end
|
28
|
-
|
29
|
-
unless File.exists? db_path
|
30
|
-
say "Specified DB does not exist: #{db_path}"
|
31
|
-
return
|
32
|
-
end
|
33
|
-
|
34
|
-
db = Daygram::Database.new(db_path)
|
35
|
-
|
36
|
-
if task == 'all'
|
37
|
-
output = db.all
|
38
|
-
elsif task == 'last'
|
39
|
-
require 'pry'
|
40
|
-
binding.pry
|
41
|
-
output = db.last()
|
42
|
-
elsif task == 'latest'
|
43
|
-
output = db.latest
|
44
|
-
end
|
45
|
-
|
46
|
-
if options[:format] == 'hash'
|
47
|
-
pp output.to_hash
|
48
|
-
elsif options[:format] == 'json'
|
49
|
-
pp output.to_json
|
50
|
-
elsif options[:format] == 'table'
|
51
|
-
say Terminal::Table.new :title => "Daygram Diary", :headings => output.diary_fields, :rows => output.to_array
|
52
|
-
else
|
53
|
-
say output.to_s
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|