work-md 0.4.5 → 0.4.9
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 +45 -0
- data/lib/work/md/commands/parse.rb +3 -27
- data/lib/work/md/commands/tomorrow.rb +15 -0
- data/lib/work/md/date_file.rb +58 -10
- data/lib/work/md/file.rb +13 -13
- 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: 3333dbe54859ef57acade3b997c337b6994b64e681369e782e39a80fb478632d
|
4
|
+
data.tar.gz: e7de4d34bf2c5eb846fa160bf0cff93250216dbc45daa6b26035ac3a3784ede6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea36e20ab31b4237157d55327978cba6c64c3b4f02df9987fcb56993b1af1826fa7ed5dbe2371ee83a0e06d6e2987126010e34351694f6fdb2538c68bafc356
|
7
|
+
data.tar.gz: 9bb98607f7e1ed8d426164b5b28a8f0406160405706adb3f2bbfcb90af6cb4cfe860b35672d147742f47fa9c89c665f4582f6a43fe4e229374ea901122f7cca3
|
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_paths = Work::Md::DateFile.list_file_paths_by_argv_query(argv)
|
12
|
+
|
13
|
+
if file_paths == []
|
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_paths.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 or the date sent is invalid!",
|
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,45 @@
|
|
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_paths =
|
10
|
+
Work::Md::DateFile.list_file_paths_by_argv_query(
|
11
|
+
argv,
|
12
|
+
create_inexistent: true
|
13
|
+
)
|
14
|
+
|
15
|
+
if file_paths == []
|
16
|
+
puts ::TTY::Box.frame(
|
17
|
+
"message: File(s) not found!",
|
18
|
+
**Work::Md::Cli.error_frame_style
|
19
|
+
)
|
20
|
+
|
21
|
+
return
|
22
|
+
end
|
23
|
+
|
24
|
+
Work::Md::File.open_in_editor(file_paths)
|
25
|
+
rescue
|
26
|
+
Work::Md::Cli.help(
|
27
|
+
::TTY::Box.frame(
|
28
|
+
"message: Some error occurred interpreting your command or the date sent is invalid!",
|
29
|
+
'',
|
30
|
+
'Usage examples:',
|
31
|
+
'',
|
32
|
+
'work-md o -d=1 -m=5 -y=2000 # open day 1 from month 5 and year 2000',
|
33
|
+
'work-md o -d=1,2,3 # open day 1, 2 and 3 from the current month and year',
|
34
|
+
'work-md o -d=1,2 -m=4 # open day 1 and 2 from month 4 and current year',
|
35
|
+
'work-md o -d=1..10 -m=4 # open day 1 to 10 from month 4 and current year',
|
36
|
+
'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',
|
37
|
+
**Work::Md::Cli.error_frame_style
|
38
|
+
)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -7,34 +7,10 @@ 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_paths_by_argv_query(argv)
|
13
|
+
.each { |file_path| parser.add_file(file_path) }
|
38
14
|
|
39
15
|
Work::Md::File.create_and_open_parsed(parser)
|
40
16
|
rescue Work::Md::Parser::Error => e
|
data/lib/work/md/date_file.rb
CHANGED
@@ -3,25 +3,63 @@
|
|
3
3
|
module Work
|
4
4
|
module Md
|
5
5
|
class DateFile
|
6
|
-
def self.open_or_create(some_date
|
6
|
+
def self.open_or_create(some_date)
|
7
7
|
Work::Md::File.open_in_editor(
|
8
|
-
[create_if_not_exist(some_date
|
8
|
+
[create_if_not_exist(some_date)]
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.
|
13
|
-
|
14
|
-
|
12
|
+
def self.list_file_paths_by_argv_query(argv, create_inexistent: false)
|
13
|
+
file_paths = []
|
14
|
+
|
15
|
+
argv_keys_to_files = -> (argv_keys, acc_file_paths) {
|
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_acc = lambda do |day|
|
22
|
+
day = "0#{day.to_i}" if day.to_i < 10
|
23
|
+
|
24
|
+
file_path = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
|
15
25
|
|
16
|
-
|
26
|
+
if create_inexistent
|
27
|
+
create_if_not_exist(DateTime.new(year.to_i, month.to_i, day.to_i))
|
17
28
|
|
18
|
-
|
29
|
+
acc_file_paths.push(file_path)
|
30
|
+
elsif ::File.exist? file_path
|
31
|
+
acc_file_paths.push(file_path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if argv_keys['d'].include?('..')
|
36
|
+
range = argv_keys['d'].split('..')
|
37
|
+
|
38
|
+
(range[0].to_i..range[1].to_i).each { |day| add_file_to_acc.call(day) }
|
39
|
+
else
|
40
|
+
argv_keys['d'].split(',').each { |day| add_file_to_acc.call(day) }
|
41
|
+
end
|
42
|
+
|
43
|
+
acc_file_paths
|
44
|
+
}
|
45
|
+
|
46
|
+
argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
|
47
|
+
argv_keys_to_files.(Work::Md::Cli.fetch_argv_keys(args), file_paths)
|
48
|
+
end
|
49
|
+
|
50
|
+
file_paths
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.create_if_not_exist(some_date)
|
54
|
+
t = Work::Md::Config.translations
|
55
|
+
file = date_to_file_locations(some_date)
|
56
|
+
return file[:name] if ::File.exist?(file[:path])
|
19
57
|
|
20
58
|
::FileUtils
|
21
|
-
.mkdir_p(
|
59
|
+
.mkdir_p(file[:dir])
|
22
60
|
|
23
61
|
::File.open(
|
24
|
-
|
62
|
+
file[:path],
|
25
63
|
'w+'
|
26
64
|
) do |f|
|
27
65
|
f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{Work::Md::Config.title} \n\n")
|
@@ -41,7 +79,17 @@ module Work
|
|
41
79
|
f.puts("0\n\n")
|
42
80
|
end
|
43
81
|
|
44
|
-
|
82
|
+
file[:name]
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.date_to_file_locations(some_date)
|
86
|
+
work_dir = Work::Md::Config.work_dir
|
87
|
+
|
88
|
+
{
|
89
|
+
name: "#{some_date.strftime('%Y/%m/%d')}.md",
|
90
|
+
dir: "#{work_dir}/#{some_date.strftime('%Y/%m')}",
|
91
|
+
path: "#{work_dir}/#{some_date.strftime('%Y/%m/%d')}.md"
|
92
|
+
}
|
45
93
|
end
|
46
94
|
end
|
47
95
|
end
|
data/lib/work/md/file.rb
CHANGED
@@ -3,19 +3,6 @@
|
|
3
3
|
module Work
|
4
4
|
module Md
|
5
5
|
class File
|
6
|
-
def self.open_in_editor(file_names = [], dir: nil)
|
7
|
-
editor = Work::Md::Config.editor
|
8
|
-
work_dir = dir || Work::Md::Config.work_dir
|
9
|
-
|
10
|
-
::FileUtils.cd(work_dir) do
|
11
|
-
ENV['EDITOR'] = editor unless editor.nil?
|
12
|
-
|
13
|
-
return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
|
14
|
-
|
15
|
-
::TTY::Editor.open(file_names[0], file_names[1])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
6
|
def self.create_and_open_parsed(parser)
|
20
7
|
parser.freeze
|
21
8
|
|
@@ -76,6 +63,19 @@ module Work
|
|
76
63
|
|
77
64
|
Work::Md::File.open_in_editor([parsed_file_path])
|
78
65
|
end
|
66
|
+
|
67
|
+
def self.open_in_editor(file_names = [])
|
68
|
+
editor = Work::Md::Config.editor
|
69
|
+
work_dir = Work::Md::Config.work_dir
|
70
|
+
|
71
|
+
::FileUtils.cd(work_dir) do
|
72
|
+
ENV['EDITOR'] = editor unless editor.nil?
|
73
|
+
|
74
|
+
return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
|
75
|
+
|
76
|
+
::TTY::Editor.open(*file_names)
|
77
|
+
end
|
78
|
+
end
|
79
79
|
end
|
80
80
|
end
|
81
81
|
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.9
|
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:
|
11
|
+
date: 2022-09-12 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
|