work-md 0.4.2 → 0.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f71380cbbd01039015727e92f5de5e621b1a3511914e4a6b81ef50de192ea43d
4
- data.tar.gz: 7952a1d0d8c232a40ac18bdf90ff5f3b728aa57b3868170821204136492b04ff
3
+ metadata.gz: f5ab4b3285e24c96c695dbded250664fc83981e18794011d77a9ecaae7556359
4
+ data.tar.gz: 93e48d1e25b612021ae73de244767c4ccf905cae237dc8a6361a3331bd179451
5
5
  SHA512:
6
- metadata.gz: 11d3bc8deb4aa7ba041a171a28b825eed5ce1690a53644ab331583f219f970a58c1dfcfcf7c95460e4ab2634efad01f5bdfe9e68a754da7f859ae40c43ab9a5d
7
- data.tar.gz: e4a5616a87b0d249ef703b775f6956af217f578bd9fc3cd88e2becd43a45d96f5daed154704e174c7e1724cf703234be2e848e5e805932275b407727c709cef6
6
+ metadata.gz: 8a55fd04880ddd3c4d31d556e0165794370248a681888de20ed7cd2d4650d281e0aa56e28f407fe07ea3c84d54226e79d9521e5855e484220490169214477c83
7
+ data.tar.gz: d462dc1ab849cb87a1cce0882350db98e53f7edbf1ed7907fdb2bd57016f73ecb607fca551c6b8d3302f8122f161e7e286cd9a05b87fba92544252458a087e37
data/lib/work/md/cli.rb CHANGED
@@ -15,11 +15,20 @@ module Work
15
15
  'pl' => 'plast',
16
16
  'a' => 'annotations',
17
17
  'l' => 'last',
18
+ 'o' => 'open',
18
19
  'tl' => 'tlast'
19
20
  }.freeze
20
21
 
21
22
  def self.execute(argv)
22
23
  first_argv_argument = argv.shift
24
+ tag = fetch_argv_keys(argv)['tag']
25
+
26
+ if tag
27
+ ENV['WORK_MD_TAG'] = tag
28
+ argv.reject! { |arg| arg.include?('-tag=') }
29
+ end
30
+
31
+ ::FileUtils.mkdir_p(Work::Md::Config.work_dir)
23
32
 
24
33
  raise CommandMissing if first_argv_argument.nil?
25
34
 
@@ -30,7 +39,7 @@ module Work
30
39
  Object
31
40
  .const_get("Work::Md::Commands::#{command}")
32
41
  .send(:execute, argv)
33
- rescue NameError => e
42
+ rescue NameError
34
43
  puts help(
35
44
  ::TTY::Box.frame(
36
45
  "Command '#{first_argv_argument}' not found!",
@@ -56,22 +65,34 @@ module Work
56
65
  '- work-md last',
57
66
  '- work-md tlast',
58
67
  '- work-md parse',
68
+ '- work-md plast',
59
69
  '- work-md annotations',
70
+ '- work-md open',
60
71
  '- work-md config',
61
72
  '',
62
- 'more information in github.com/work-md',
63
- padding: 1,
64
- title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
73
+ 'for more information: github.com/work-md',
74
+ **normal_frame_style
65
75
  )
66
76
  # rubocop:enable Layout/LineLength
67
77
  end
68
78
 
79
+ def self.normal_frame_style
80
+ {
81
+ padding: 1,
82
+ title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
83
+ }
84
+ end
85
+
69
86
  def self.error_frame_style
70
87
  {
71
88
  padding: 1,
72
89
  title: { top_left: '(error)' }
73
90
  }
74
91
  end
92
+
93
+ def self.fetch_argv_keys(argv)
94
+ Hash[argv.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
95
+ end
75
96
  end
76
97
  end
77
98
  end
@@ -5,31 +5,74 @@ module Work
5
5
  module Commands
6
6
  class Last
7
7
  class << self
8
- def execute(_argv = [])
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
- (1..160).each do
14
- file_name = "#{current_day.strftime('%Y/%m/%d')}.md"
11
+ if argv == []
12
+ current_day = Date.today.prev_day
13
+ found_file = false
15
14
 
16
- if ::File.exist?("#{work_dir}/#{file_name}")
17
- Work::Md::File.open_in_editor([file_name])
18
- found_file = true
19
- break
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
- current_day = current_day.prev_day
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
- unless found_file
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: No file found in last 5 months",
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,72 @@
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
+ to_open = []
10
+
11
+ argv_keys_to_parser = -> (argv_keys, received_to_open) {
12
+ year = argv_keys['y'] || Time.new.year
13
+ month = argv_keys['m'] || Time.new.month
14
+
15
+ month = "0#{month.to_i}" if month.to_i < 10
16
+
17
+ add_file_to_parser = lambda do |day|
18
+ day = "0#{day.to_i}" if day.to_i < 10
19
+
20
+ file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
21
+
22
+ if ::File.exist? file_name
23
+ received_to_open.push(file_name)
24
+ end
25
+ end
26
+
27
+ if argv_keys['d'].include?('..')
28
+ range = argv_keys['d'].split('..')
29
+
30
+ (range[0].to_i..range[1].to_i).each { |day| add_file_to_parser.call(day) }
31
+ else
32
+ argv_keys['d'].split(',').each { |day| add_file_to_parser.call(day) }
33
+ end
34
+
35
+ received_to_open
36
+ }
37
+
38
+ argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
39
+ argv_keys_to_parser.(Work::Md::Cli.fetch_argv_keys(args), to_open)
40
+ end
41
+
42
+ if to_open == []
43
+ puts ::TTY::Box.frame(
44
+ "message: File(s) not found!",
45
+ **Work::Md::Cli.error_frame_style
46
+ )
47
+
48
+ return
49
+ end
50
+
51
+ Work::Md::File.open_in_editor(to_open)
52
+ rescue StandardError
53
+ Work::Md::Cli.help(
54
+ ::TTY::Box.frame(
55
+ "message: Some error occurred interpreting your command!",
56
+ '',
57
+ 'Usage examples:',
58
+ '',
59
+ 'work-md o -d=1 -m=5 -y=2000 # open day 1 from month 5 and year 2000',
60
+ 'work-md o -d=1,2,3 # open day 1, 2 and 3 from the current month and year',
61
+ 'work-md o -d=1,2 -m=4 # open day 1 and 2 from month 4 and current year',
62
+ 'work-md o -d=1..10 -m=4 # open day 1 to 10 from month 4 and current year',
63
+ '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',
64
+ **Work::Md::Cli.error_frame_style
65
+ )
66
+ )
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -7,9 +7,9 @@ module Work
7
7
  class << self
8
8
  def execute(argv = [])
9
9
  parser = Work::Md::Parser::Engine.new
10
- args_hash_to_parser = -> (args, received_parser) {
11
- year = args['y'] || Time.new.year
12
- month = args['m'] || Time.new.month
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
13
 
14
14
  month = "0#{month.to_i}" if month.to_i < 10
15
15
 
@@ -21,27 +21,28 @@ module Work
21
21
  received_parser.add_file(file_name)
22
22
  end
23
23
 
24
- if args['d'].include?('..')
25
- range = args['d'].split('..')
24
+ if argv_keys['d'].include?('..')
25
+ range = argv_keys['d'].split('..')
26
26
 
27
27
  (range[0].to_i..range[1].to_i).each { |day| add_file_to_parser.call(day) }
28
28
  else
29
- args['d'].split(',').each { |day| add_file_to_parser.call(day) }
29
+ argv_keys['d'].split(',').each { |day| add_file_to_parser.call(day) }
30
30
  end
31
31
 
32
32
  received_parser
33
33
  }
34
34
 
35
35
  argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
36
- args_hash = Hash[args.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
37
- args_hash_to_parser.(args_hash, parser)
36
+ argv_keys_to_parser.(Work::Md::Cli.fetch_argv_keys(args), parser)
38
37
  end
39
38
 
40
39
  Work::Md::File.create_and_open_parsed(parser)
41
- rescue StandardError => e
40
+ rescue Work::Md::Parser::Error => e
41
+ Work::Md::Cli.help(e.message)
42
+ rescue StandardError
42
43
  Work::Md::Cli.help(
43
44
  ::TTY::Box.frame(
44
- "message: #{e.message}",
45
+ "message: Some of verified markdown files may be with an incorrect format",
45
46
  '',
46
47
  'Usage examples:',
47
48
  '',
@@ -6,7 +6,26 @@ module Work
6
6
  class Plast
7
7
  class << self
8
8
  def execute(argv = [])
9
- last_n = argv.first.to_i
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,6 +42,19 @@ module Work
23
42
  end
24
43
 
25
44
  Work::Md::File.create_and_open_parsed(parser)
45
+ rescue Work::Md::Parser::Error => e
46
+ Work::Md::Cli.help(e.message)
47
+ rescue StandardError => e
48
+ Work::Md::Cli.help(
49
+ ::TTY::Box.frame(
50
+ "message: Some of verified markdown files may be with an incorrect format",
51
+ '',
52
+ 'Usage example:',
53
+ '',
54
+ 'work-md pl 7 # parse the last 7 days',
55
+ **Work::Md::Cli.error_frame_style
56
+ )
57
+ )
26
58
  end
27
59
  end
28
60
  end
data/lib/work/md/file.rb CHANGED
@@ -72,9 +72,9 @@ module Work
72
72
  end
73
73
 
74
74
  f.puts("\n\n")
75
-
76
- Work::Md::File.open_in_editor([parsed_file_path])
77
75
  end
76
+
77
+ Work::Md::File.open_in_editor([parsed_file_path])
78
78
  end
79
79
  end
80
80
  end
@@ -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
- return content.split("#{start_with}:\n")[1] unless start_with.nil?
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.4.2'
5
+ VERSION = '0.4.6'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -11,6 +11,7 @@ require_relative 'md/commands/tyesterday'
11
11
  require_relative 'md/commands/annotations'
12
12
  require_relative 'md/commands/last'
13
13
  require_relative 'md/commands/tlast'
14
+ require_relative 'md/commands/open'
14
15
  require_relative 'md/parser/engine'
15
16
  require_relative 'md/commands/parse'
16
17
  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.2
4
+ version: 0.4.6
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-21 00:00:00.000000000 Z
11
+ date: 2021-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -55,6 +55,7 @@ files:
55
55
  - lib/work/md/commands/annotations.rb
56
56
  - lib/work/md/commands/config.rb
57
57
  - lib/work/md/commands/last.rb
58
+ - lib/work/md/commands/open.rb
58
59
  - lib/work/md/commands/parse.rb
59
60
  - lib/work/md/commands/plast.rb
60
61
  - lib/work/md/commands/tlast.rb