work-md 0.4.3 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/work/md/cli.rb +13 -2
- data/lib/work/md/commands/delete.rb +47 -0
- data/lib/work/md/commands/last.rb +55 -12
- data/lib/work/md/commands/open.rb +41 -0
- data/lib/work/md/commands/parse.rb +5 -27
- data/lib/work/md/commands/plast.rb +23 -2
- data/lib/work/md/commands/tomorrow.rb +15 -0
- data/lib/work/md/date_file.rb +35 -0
- data/lib/work/md/file.rb +2 -2
- data/lib/work/md/parser/engine.rb +30 -8
- data/lib/work/md/version.rb +1 -1
- data/lib/work/md.rb +3 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d958b459035344108c414ccf382b6bce83acba70585accb0c4584b634d62808
|
4
|
+
data.tar.gz: db98f8a2b2a2d5dacd81cfa3951b92407455e0dffacd15e2d6e08ca6f237a98c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48b5aad2d02b382d86ccf273518f87ccfd3fd7248feac6de4eca364461019533dd3497066c99139dac7c34ade603459ab806f35d646ad8cfadb664bb8e4fcfc7
|
7
|
+
data.tar.gz: 5d8e4ab76582f9e462a2d6286d1f5aef1a26b8e118a0f8c711ce36e1917f5f9c500c24c3357b5ef1985060d75cc0a3a777c14ef7ceba055e0791ceb41fee119c
|
data/lib/work/md/cli.rb
CHANGED
@@ -10,10 +10,13 @@ module Work
|
|
10
10
|
't' => 'today',
|
11
11
|
'ty' => 'tyesterday',
|
12
12
|
'y' => 'yesterday',
|
13
|
+
'to' => 'tomorrow',
|
13
14
|
'c' => 'config',
|
14
15
|
'p' => 'parse',
|
15
16
|
'pl' => 'plast',
|
16
17
|
'a' => 'annotations',
|
18
|
+
'o' => 'open',
|
19
|
+
'd' => 'delete',
|
17
20
|
'l' => 'last',
|
18
21
|
'tl' => 'tlast'
|
19
22
|
}.freeze
|
@@ -61,20 +64,28 @@ module Work
|
|
61
64
|
'- work-md today',
|
62
65
|
'- work-md yesterday',
|
63
66
|
'- work-md tyesterday',
|
67
|
+
'- work-md tomorrow',
|
64
68
|
'- work-md last',
|
65
69
|
'- work-md tlast',
|
66
70
|
'- work-md parse',
|
67
71
|
'- work-md plast',
|
68
72
|
'- work-md annotations',
|
73
|
+
'- work-md open',
|
69
74
|
'- work-md config',
|
70
75
|
'',
|
71
76
|
'for more information: github.com/work-md',
|
72
|
-
|
73
|
-
title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
|
77
|
+
**normal_frame_style
|
74
78
|
)
|
75
79
|
# rubocop:enable Layout/LineLength
|
76
80
|
end
|
77
81
|
|
82
|
+
def self.normal_frame_style
|
83
|
+
{
|
84
|
+
padding: 1,
|
85
|
+
title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
78
89
|
def self.error_frame_style
|
79
90
|
{
|
80
91
|
padding: 1,
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Work
|
4
|
+
module Md
|
5
|
+
module Commands
|
6
|
+
class Delete
|
7
|
+
class << self
|
8
|
+
def execute(argv = [])
|
9
|
+
prompt = TTY::Prompt.new
|
10
|
+
|
11
|
+
file_names = Work::Md::DateFile.list_file_names_by_argv_query(argv)
|
12
|
+
|
13
|
+
if file_names == []
|
14
|
+
puts ::TTY::Box.frame(
|
15
|
+
"message: File(s) not found!",
|
16
|
+
**Work::Md::Cli.error_frame_style
|
17
|
+
)
|
18
|
+
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
file_names.each do |file_name|
|
23
|
+
if prompt.yes?("Do you really want to delete \"#{file_name}\"!?")
|
24
|
+
::File.delete(file_name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue StandardError
|
28
|
+
Work::Md::Cli.help(
|
29
|
+
::TTY::Box.frame(
|
30
|
+
"message: Some error occurred interpreting your command!",
|
31
|
+
'',
|
32
|
+
'Usage examples:',
|
33
|
+
'',
|
34
|
+
'work-md d -d=1 -m=5 -y=2000 # delete day 1 from month 5 and year 2000',
|
35
|
+
'work-md d -d=1,2,3 # delete day 1, 2 and 3 from the current month and year',
|
36
|
+
'work-md d -d=1,2 -m=4 # delete day 1 and 2 from month 4 and current year',
|
37
|
+
'work-md d -d=1..10 -m=4 # delete day 1 to 10 from month 4 and current year',
|
38
|
+
'work-md d -d=1..25 -m=2 and -d=1..25 -m=2 -y=1999 # delete day 1 to 25 from month 2 and current year and 1 to 25 from month 2 in 1999',
|
39
|
+
**Work::Md::Cli.error_frame_style
|
40
|
+
)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -5,31 +5,74 @@ module Work
|
|
5
5
|
module Commands
|
6
6
|
class Last
|
7
7
|
class << self
|
8
|
-
def execute(
|
9
|
-
found_file = false
|
10
|
-
current_day = Date.today.prev_day
|
8
|
+
def execute(argv = [])
|
11
9
|
work_dir = Work::Md::Config.work_dir
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
if argv == []
|
12
|
+
current_day = Date.today.prev_day
|
13
|
+
found_file = false
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
(1..160).each do
|
16
|
+
file_name = "#{current_day.strftime('%Y/%m/%d')}.md"
|
17
|
+
|
18
|
+
if ::File.exist?("#{work_dir}/#{file_name}")
|
19
|
+
Work::Md::File.open_in_editor([file_name])
|
20
|
+
found_file = true
|
21
|
+
break
|
22
|
+
end
|
23
|
+
|
24
|
+
current_day = current_day.prev_day
|
20
25
|
end
|
21
26
|
|
22
|
-
|
27
|
+
unless found_file
|
28
|
+
Work::Md::Cli.help(
|
29
|
+
::TTY::Box.frame(
|
30
|
+
"message: No file found in last 5 months",
|
31
|
+
**Work::Md::Cli.error_frame_style
|
32
|
+
)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
return
|
23
37
|
end
|
24
38
|
|
25
|
-
|
39
|
+
to_open = []
|
40
|
+
is_numeric = ->(str) {
|
41
|
+
str == "#{str.to_f}" || str == "#{str.to_i}"
|
42
|
+
}
|
43
|
+
|
44
|
+
if is_numeric.(argv.first)
|
45
|
+
last_n = argv.first.to_i
|
46
|
+
else
|
26
47
|
Work::Md::Cli.help(
|
27
48
|
::TTY::Box.frame(
|
28
|
-
"message:
|
49
|
+
"message: 'last' command accept only numeric arguments, you give: #{argv.inspect}",
|
50
|
+
'',
|
51
|
+
'Usage example:',
|
52
|
+
'',
|
53
|
+
'work-md l 7 # open the last 7 days',
|
54
|
+
'work-md l # open the last day',
|
29
55
|
**Work::Md::Cli.error_frame_style
|
30
56
|
)
|
31
57
|
)
|
58
|
+
return
|
32
59
|
end
|
60
|
+
|
61
|
+
last_date = Date.today.prev_day
|
62
|
+
|
63
|
+
(1..last_n).map do
|
64
|
+
last_file_name = "#{last_date.strftime('%Y/%m/%d')}.md"
|
65
|
+
|
66
|
+
if ::File.exist?("#{work_dir}/#{last_file_name}")
|
67
|
+
to_open.push("#{work_dir}/#{last_file_name}")
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
last_date = last_date.prev_day
|
73
|
+
end
|
74
|
+
|
75
|
+
Work::Md::File.open_in_editor(to_open)
|
33
76
|
end
|
34
77
|
end
|
35
78
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Work
|
4
|
+
module Md
|
5
|
+
module Commands
|
6
|
+
class Open
|
7
|
+
class << self
|
8
|
+
def execute(argv = [])
|
9
|
+
file_names = Work::Md::DateFile.list_file_names_by_argv_query(argv)
|
10
|
+
|
11
|
+
if file_names == []
|
12
|
+
puts ::TTY::Box.frame(
|
13
|
+
"message: File(s) not found!",
|
14
|
+
**Work::Md::Cli.error_frame_style
|
15
|
+
)
|
16
|
+
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
Work::Md::File.open_in_editor(file_names)
|
21
|
+
rescue StandardError
|
22
|
+
Work::Md::Cli.help(
|
23
|
+
::TTY::Box.frame(
|
24
|
+
"message: Some error occurred interpreting your command!",
|
25
|
+
'',
|
26
|
+
'Usage examples:',
|
27
|
+
'',
|
28
|
+
'work-md o -d=1 -m=5 -y=2000 # open day 1 from month 5 and year 2000',
|
29
|
+
'work-md o -d=1,2,3 # open day 1, 2 and 3 from the current month and year',
|
30
|
+
'work-md o -d=1,2 -m=4 # open day 1 and 2 from month 4 and current year',
|
31
|
+
'work-md o -d=1..10 -m=4 # open day 1 to 10 from month 4 and current year',
|
32
|
+
'work-md o -d=1..25 -m=2 and -d=1..25 -m=2 -y=1999 # open day 1 to 25 from month 2 and current year and 1 to 25 from month 2 in 1999',
|
33
|
+
**Work::Md::Cli.error_frame_style
|
34
|
+
)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -7,36 +7,14 @@ module Work
|
|
7
7
|
class << self
|
8
8
|
def execute(argv = [])
|
9
9
|
parser = Work::Md::Parser::Engine.new
|
10
|
-
argv_keys_to_parser = -> (argv_keys, received_parser) {
|
11
|
-
year = argv_keys['y'] || Time.new.year
|
12
|
-
month = argv_keys['m'] || Time.new.month
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
day = "0#{day.to_i}" if day.to_i < 10
|
18
|
-
|
19
|
-
file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
|
20
|
-
|
21
|
-
received_parser.add_file(file_name)
|
22
|
-
end
|
23
|
-
|
24
|
-
if argv_keys['d'].include?('..')
|
25
|
-
range = argv_keys['d'].split('..')
|
26
|
-
|
27
|
-
(range[0].to_i..range[1].to_i).each { |day| add_file_to_parser.call(day) }
|
28
|
-
else
|
29
|
-
argv_keys['d'].split(',').each { |day| add_file_to_parser.call(day) }
|
30
|
-
end
|
31
|
-
|
32
|
-
received_parser
|
33
|
-
}
|
34
|
-
|
35
|
-
argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
|
36
|
-
argv_keys_to_parser.(Work::Md::Cli.fetch_argv_keys(args), parser)
|
37
|
-
end
|
11
|
+
Work::Md::DateFile
|
12
|
+
.list_file_names_by_argv_query(argv)
|
13
|
+
.each { |file_name| parser.add_file(file_name) }
|
38
14
|
|
39
15
|
Work::Md::File.create_and_open_parsed(parser)
|
16
|
+
rescue Work::Md::Parser::Error => e
|
17
|
+
Work::Md::Cli.help(e.message)
|
40
18
|
rescue StandardError
|
41
19
|
Work::Md::Cli.help(
|
42
20
|
::TTY::Box.frame(
|
@@ -6,7 +6,26 @@ module Work
|
|
6
6
|
class Plast
|
7
7
|
class << self
|
8
8
|
def execute(argv = [])
|
9
|
-
|
9
|
+
is_numeric = ->(str) {
|
10
|
+
str == "#{str.to_f}" || str == "#{str.to_i}"
|
11
|
+
}
|
12
|
+
|
13
|
+
if is_numeric.(argv.first)
|
14
|
+
last_n = argv.first.to_i
|
15
|
+
else
|
16
|
+
Work::Md::Cli.help(
|
17
|
+
::TTY::Box.frame(
|
18
|
+
"message: 'plast' command accept only numeric arguments, you give: #{argv.inspect}",
|
19
|
+
'',
|
20
|
+
'Usage example:',
|
21
|
+
'',
|
22
|
+
'work-md pl 7 # parse the last 7 days',
|
23
|
+
**Work::Md::Cli.error_frame_style
|
24
|
+
)
|
25
|
+
)
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
10
29
|
last_date = Date.today.prev_day
|
11
30
|
work_dir = Work::Md::Config.work_dir
|
12
31
|
parser = Work::Md::Parser::Engine.new
|
@@ -23,7 +42,9 @@ module Work
|
|
23
42
|
end
|
24
43
|
|
25
44
|
Work::Md::File.create_and_open_parsed(parser)
|
26
|
-
rescue
|
45
|
+
rescue Work::Md::Parser::Error => e
|
46
|
+
Work::Md::Cli.help(e.message)
|
47
|
+
rescue StandardError => e
|
27
48
|
Work::Md::Cli.help(
|
28
49
|
::TTY::Box.frame(
|
29
50
|
"message: Some of verified markdown files may be with an incorrect format",
|
data/lib/work/md/date_file.rb
CHANGED
@@ -9,6 +9,41 @@ module Work
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.list_file_names_by_argv_query(argv)
|
13
|
+
file_names = []
|
14
|
+
|
15
|
+
argv_keys_to_files = -> (argv_keys, acc_file_names) {
|
16
|
+
year = argv_keys['y'] || Time.new.year
|
17
|
+
month = argv_keys['m'] || Time.new.month
|
18
|
+
|
19
|
+
month = "0#{month.to_i}" if month.to_i < 10
|
20
|
+
|
21
|
+
add_file_to_open = lambda do |day|
|
22
|
+
day = "0#{day.to_i}" if day.to_i < 10
|
23
|
+
|
24
|
+
file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
|
25
|
+
|
26
|
+
acc_file_names.push(file_name) if ::File.exist? file_name
|
27
|
+
end
|
28
|
+
|
29
|
+
if argv_keys['d'].include?('..')
|
30
|
+
range = argv_keys['d'].split('..')
|
31
|
+
|
32
|
+
(range[0].to_i..range[1].to_i).each { |day| add_file_to_open.call(day) }
|
33
|
+
else
|
34
|
+
argv_keys['d'].split(',').each { |day| add_file_to_open.call(day) }
|
35
|
+
end
|
36
|
+
|
37
|
+
acc_file_names
|
38
|
+
}
|
39
|
+
|
40
|
+
argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
|
41
|
+
argv_keys_to_files.(Work::Md::Cli.fetch_argv_keys(args), file_names)
|
42
|
+
end
|
43
|
+
|
44
|
+
file_names
|
45
|
+
end
|
46
|
+
|
12
47
|
def self.create_if_not_exist(some_date, dir: nil)
|
13
48
|
t = Work::Md::Config.translations
|
14
49
|
work_dir = dir || Work::Md::Config.work_dir
|
data/lib/work/md/file.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'date'
|
4
|
+
|
3
5
|
module Work
|
4
6
|
module Md
|
5
7
|
module Parser
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
6
10
|
# rubocop:disable Metrics/ClassLength
|
7
11
|
class Engine
|
8
12
|
IS_FROZEN_ERROR_MESSAGE = 'Work::Md::Parser::Engine is frozen'
|
@@ -28,7 +32,7 @@ module Work
|
|
28
32
|
raise IS_FROZEN_ERROR_MESSAGE if @frozen
|
29
33
|
|
30
34
|
begin
|
31
|
-
file_content = ::File.read(file)
|
35
|
+
file_content = ::File.read(file).squeeze(' ').strip
|
32
36
|
rescue Errno::ENOENT
|
33
37
|
return
|
34
38
|
end
|
@@ -108,12 +112,12 @@ module Work
|
|
108
112
|
|
109
113
|
@days_bars ||=
|
110
114
|
@parsed_files.map do |f|
|
111
|
-
pom = (1..f.pomodoros).map { '⬛' }.join
|
112
|
-
mee = f.meetings.map { '📅' }.join
|
113
|
-
int = f.interruptions.map { '⚠️' }.join
|
114
|
-
dif = f.difficulties.map { '😓' }.join
|
115
|
-
obs = f.observations.map { '📝' }.join
|
116
|
-
tas = f.tasks.map { '✔️' }.join
|
115
|
+
pom = (1..f.pomodoros).map { '⬛' }.join if f.pomodoros
|
116
|
+
mee = f.meetings.map { '📅' }.join if f.meetings
|
117
|
+
int = f.interruptions.map { '⚠️' }.join if f.interruptions
|
118
|
+
dif = f.difficulties.map { '😓' }.join if f.difficulties
|
119
|
+
obs = f.observations.map { '📝' }.join if f.observations
|
120
|
+
tas = f.tasks.map { '✔️' }.join if f.tasks
|
117
121
|
|
118
122
|
"(#{f.date}) #{pom}#{mee}#{int}#{dif}#{obs}#{tas}"
|
119
123
|
end
|
@@ -170,6 +174,19 @@ module Work
|
|
170
174
|
parsed_file.pomodoros =
|
171
175
|
parse_pomodoro(content, start_with: @t[:pomodoros])
|
172
176
|
end
|
177
|
+
rescue StandardError
|
178
|
+
# TODO: Write tests for this scenario
|
179
|
+
file_name = Date.strptime(parsed_file.date, '%d/%m/%Y').strftime('%Y/%m/%d.md')
|
180
|
+
message = ::TTY::Box.frame(
|
181
|
+
"message: Cannot parse file '#{file_name}' maybe it's in an incorrect format.",
|
182
|
+
'',
|
183
|
+
'Usage example:',
|
184
|
+
'',
|
185
|
+
'work-md pl 7 # parse the last 7 days',
|
186
|
+
**Work::Md::Cli.error_frame_style
|
187
|
+
)
|
188
|
+
|
189
|
+
raise Error, message
|
173
190
|
end
|
174
191
|
# rubocop:enable Metrics/CyclomaticComplexity
|
175
192
|
# rubocop:enable Metrics/PerceivedComplexity
|
@@ -187,7 +204,12 @@ module Work
|
|
187
204
|
end
|
188
205
|
|
189
206
|
def basic_parse(content, start_with: nil)
|
190
|
-
|
207
|
+
unless start_with.nil?
|
208
|
+
return content
|
209
|
+
.split("#{start_with}:")[1]
|
210
|
+
.squeeze(' ')
|
211
|
+
.sub("\n\n", "\n")
|
212
|
+
end
|
191
213
|
|
192
214
|
content.split(":\n\n")[1]
|
193
215
|
end
|
data/lib/work/md/version.rb
CHANGED
data/lib/work/md.rb
CHANGED
@@ -7,10 +7,13 @@ require_relative 'md/date_file'
|
|
7
7
|
require_relative 'md/commands/today'
|
8
8
|
require_relative 'md/commands/config'
|
9
9
|
require_relative 'md/commands/yesterday'
|
10
|
+
require_relative 'md/commands/tomorrow'
|
10
11
|
require_relative 'md/commands/tyesterday'
|
11
12
|
require_relative 'md/commands/annotations'
|
12
13
|
require_relative 'md/commands/last'
|
13
14
|
require_relative 'md/commands/tlast'
|
15
|
+
require_relative 'md/commands/open'
|
16
|
+
require_relative 'md/commands/delete'
|
14
17
|
require_relative 'md/parser/engine'
|
15
18
|
require_relative 'md/commands/parse'
|
16
19
|
require_relative 'md/commands/plast'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: work-md
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Fernandez Teixeira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-box
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.7.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-prompt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.23.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.23.1
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- hriqueft@gmail.com
|
@@ -54,11 +68,14 @@ files:
|
|
54
68
|
- lib/work/md/cli.rb
|
55
69
|
- lib/work/md/commands/annotations.rb
|
56
70
|
- lib/work/md/commands/config.rb
|
71
|
+
- lib/work/md/commands/delete.rb
|
57
72
|
- lib/work/md/commands/last.rb
|
73
|
+
- lib/work/md/commands/open.rb
|
58
74
|
- lib/work/md/commands/parse.rb
|
59
75
|
- lib/work/md/commands/plast.rb
|
60
76
|
- lib/work/md/commands/tlast.rb
|
61
77
|
- lib/work/md/commands/today.rb
|
78
|
+
- lib/work/md/commands/tomorrow.rb
|
62
79
|
- lib/work/md/commands/tyesterday.rb
|
63
80
|
- lib/work/md/commands/yesterday.rb
|
64
81
|
- lib/work/md/config.rb
|