work-md 0.4.5 → 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: 5e11b12242f29e25b4cd175693b475d548e37c422f966cca7c4ecdd7ae7bbf23
4
- data.tar.gz: 7707b5b4ddbcf93fcfa22209eafcfd214de35cf56faec7739ed2b3239af33cd1
3
+ metadata.gz: f5ab4b3285e24c96c695dbded250664fc83981e18794011d77a9ecaae7556359
4
+ data.tar.gz: 93e48d1e25b612021ae73de244767c4ccf905cae237dc8a6361a3331bd179451
5
5
  SHA512:
6
- metadata.gz: 49da10202bf64a92baff477f92ad3cb510e8445ef4792b64298f0449680862b0b241ed8a710f047dd846ee5cf9d53930b9bc1594ca1a4e9fcaa29b6adef8ad0e
7
- data.tar.gz: 932cc585bf763de7d26eade30b48a903885ba23a17a5a6594e3d088f598a7b99fbb99414bb98b0042b2b351f7a32e740c8c0bd74f82851afd2960235ec5aa06d
6
+ metadata.gz: 8a55fd04880ddd3c4d31d556e0165794370248a681888de20ed7cd2d4650d281e0aa56e28f407fe07ea3c84d54226e79d9521e5855e484220490169214477c83
7
+ data.tar.gz: d462dc1ab849cb87a1cce0882350db98e53f7edbf1ed7907fdb2bd57016f73ecb607fca551c6b8d3302f8122f161e7e286cd9a05b87fba92544252458a087e37
data/lib/work/md/cli.rb CHANGED
@@ -15,6 +15,7 @@ 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
 
@@ -66,15 +67,22 @@ module Work
66
67
  '- work-md parse',
67
68
  '- work-md plast',
68
69
  '- work-md annotations',
70
+ '- work-md open',
69
71
  '- work-md config',
70
72
  '',
71
73
  'for more information: github.com/work-md',
72
- padding: 1,
73
- title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
74
+ **normal_frame_style
74
75
  )
75
76
  # rubocop:enable Layout/LineLength
76
77
  end
77
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
+
78
86
  def self.error_frame_style
79
87
  {
80
88
  padding: 1,
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.4.5'
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.5
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-26 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