work-md 0.4.6 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5ab4b3285e24c96c695dbded250664fc83981e18794011d77a9ecaae7556359
4
- data.tar.gz: 93e48d1e25b612021ae73de244767c4ccf905cae237dc8a6361a3331bd179451
3
+ metadata.gz: 1d958b459035344108c414ccf382b6bce83acba70585accb0c4584b634d62808
4
+ data.tar.gz: db98f8a2b2a2d5dacd81cfa3951b92407455e0dffacd15e2d6e08ca6f237a98c
5
5
  SHA512:
6
- metadata.gz: 8a55fd04880ddd3c4d31d556e0165794370248a681888de20ed7cd2d4650d281e0aa56e28f407fe07ea3c84d54226e79d9521e5855e484220490169214477c83
7
- data.tar.gz: d462dc1ab849cb87a1cce0882350db98e53f7edbf1ed7907fdb2bd57016f73ecb607fca551c6b8d3302f8122f161e7e286cd9a05b87fba92544252458a087e37
6
+ metadata.gz: 48b5aad2d02b382d86ccf273518f87ccfd3fd7248feac6de4eca364461019533dd3497066c99139dac7c34ade603459ab806f35d646ad8cfadb664bb8e4fcfc7
7
+ data.tar.gz: 5d8e4ab76582f9e462a2d6286d1f5aef1a26b8e118a0f8c711ce36e1917f5f9c500c24c3357b5ef1985060d75cc0a3a777c14ef7ceba055e0791ceb41fee119c
data/lib/work/md/cli.rb CHANGED
@@ -10,12 +10,14 @@ 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',
17
- 'l' => 'last',
18
18
  'o' => 'open',
19
+ 'd' => 'delete',
20
+ 'l' => 'last',
19
21
  'tl' => 'tlast'
20
22
  }.freeze
21
23
 
@@ -62,6 +64,7 @@ module Work
62
64
  '- work-md today',
63
65
  '- work-md yesterday',
64
66
  '- work-md tyesterday',
67
+ '- work-md tomorrow',
65
68
  '- work-md last',
66
69
  '- work-md tlast',
67
70
  '- work-md parse',
@@ -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
@@ -6,40 +6,9 @@ module Work
6
6
  class Open
7
7
  class << self
8
8
  def execute(argv = [])
9
- to_open = []
9
+ file_names = Work::Md::DateFile.list_file_names_by_argv_query(argv)
10
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 == []
11
+ if file_names == []
43
12
  puts ::TTY::Box.frame(
44
13
  "message: File(s) not found!",
45
14
  **Work::Md::Cli.error_frame_style
@@ -48,7 +17,7 @@ module Work
48
17
  return
49
18
  end
50
19
 
51
- Work::Md::File.open_in_editor(to_open)
20
+ Work::Md::File.open_in_editor(file_names)
52
21
  rescue StandardError
53
22
  Work::Md::Cli.help(
54
23
  ::TTY::Box.frame(
@@ -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
- month = "0#{month.to_i}" if month.to_i < 10
15
-
16
- add_file_to_parser = lambda do |day|
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)
40
16
  rescue Work::Md::Parser::Error => e
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Work
4
+ module Md
5
+ module Commands
6
+ class Tomorrow
7
+ class << self
8
+ def execute(_argv = [])
9
+ Work::Md::DateFile.open_or_create(Date.today.next_day)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.4.6'
5
+ VERSION = '0.4.8'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -7,11 +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'
14
15
  require_relative 'md/commands/open'
16
+ require_relative 'md/commands/delete'
15
17
  require_relative 'md/parser/engine'
16
18
  require_relative 'md/commands/parse'
17
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.6
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-12-04 00:00:00.000000000 Z
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,12 +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
58
73
  - lib/work/md/commands/open.rb
59
74
  - lib/work/md/commands/parse.rb
60
75
  - lib/work/md/commands/plast.rb
61
76
  - lib/work/md/commands/tlast.rb
62
77
  - lib/work/md/commands/today.rb
78
+ - lib/work/md/commands/tomorrow.rb
63
79
  - lib/work/md/commands/tyesterday.rb
64
80
  - lib/work/md/commands/yesterday.rb
65
81
  - lib/work/md/config.rb