rbnotes 0.4.18 → 0.4.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/CHANGELOG.md +15 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +10 -10
- data/LICENSE +1 -1
- data/exe/rbnotes +1 -0
- data/lib/rbnotes/commands/export.rb +1 -0
- data/lib/rbnotes/commands/list.rb +30 -19
- data/lib/rbnotes/commands/pick.rb +2 -1
- data/lib/rbnotes/commands/search.rb +34 -2
- data/lib/rbnotes/commands/show.rb +4 -3
- data/lib/rbnotes/conf.rb +7 -0
- data/lib/rbnotes/utils.rb +51 -5
- data/lib/rbnotes/version.rb +2 -2
- data/rbnotes.gemspec +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c983ec2e16d7e384a8b1ba50cd79ed327a1b69cf415c471becfb19dfd71ba5a2
|
4
|
+
data.tar.gz: 2147e0b2c7564fc18f664dbd39ee597dbb642a8e6b42575d71078c5cc85cc8c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2389e447037b2b9a5a9f2136b435c44cc86bc8f1b84da057ffe9b1474132564034baf539e946dc74aeafa7ba609cd81bd32c1036c60991b1959e691523a3ad9
|
7
|
+
data.tar.gz: 257fd944e264ae91780b63a9b37bfca1658943e2098ca4a007e49f05b875e4c496d475e10299496c4d397ffaa6cefe23549267bd3a0a07c8a5d6f658a37e2941
|
data/.github/workflows/main.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/).
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
|
-
-
|
8
|
+
- Fix issue #133: some tests fail.
|
9
|
+
|
10
|
+
## [0.4.20] - 2022-12-03
|
11
|
+
### Added
|
12
|
+
- Add a new keyword, `recent`. (#131)
|
13
|
+
|
14
|
+
## [0.4.19] - 2021-05-24
|
15
|
+
### Added
|
16
|
+
- Add an option to search in only the subject of each note. (#128)
|
17
|
+
|
18
|
+
### Modified
|
19
|
+
- Update copyright year in `LICENSE`. (#127)
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
- Fix #129: add description about the keyword, "all."
|
9
23
|
|
10
24
|
## [0.4.18] - 2021-04-29
|
11
25
|
### Added
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbnotes (0.4.
|
5
|
-
textrepo (~> 0.5.
|
6
|
-
unicode-display_width (~> 1.
|
4
|
+
rbnotes (0.4.20)
|
5
|
+
textrepo (~> 0.5.9)
|
6
|
+
unicode-display_width (~> 1.8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
minitest (5.
|
12
|
-
rake (13.0.
|
13
|
-
textrepo (0.5.
|
14
|
-
unicode-display_width (1.
|
11
|
+
minitest (5.16.3)
|
12
|
+
rake (13.0.6)
|
13
|
+
textrepo (0.5.9)
|
14
|
+
unicode-display_width (1.8.0)
|
15
15
|
|
16
16
|
PLATFORMS
|
17
|
-
|
17
|
+
x86_64-darwin-22
|
18
18
|
|
19
19
|
DEPENDENCIES
|
20
20
|
minitest (~> 5.0)
|
21
21
|
rake (~> 13.0)
|
22
22
|
rbnotes!
|
23
|
-
textrepo (~> 0.5.
|
23
|
+
textrepo (~> 0.5.9)
|
24
24
|
|
25
25
|
BUNDLED WITH
|
26
|
-
2.
|
26
|
+
2.3.11
|
data/LICENSE
CHANGED
data/exe/rbnotes
CHANGED
@@ -33,6 +33,8 @@ module Rbnotes::Commands
|
|
33
33
|
# - "last_week" (or "lw")
|
34
34
|
# - "this_month" (or "tm")
|
35
35
|
# - "last_month" (or "lm")
|
36
|
+
# - "recent" (or "re")
|
37
|
+
# - "all"
|
36
38
|
#
|
37
39
|
# Here is several examples of timestamp patterns.
|
38
40
|
#
|
@@ -66,9 +68,11 @@ module Rbnotes::Commands
|
|
66
68
|
|
67
69
|
utils = Rbnotes.utils
|
68
70
|
patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
|
69
|
-
|
70
71
|
repo = Textrepo.init(conf)
|
71
|
-
|
72
|
+
|
73
|
+
num_of_notes = utils.specified_recent?(args) ? conf[:number_of_recent_notes] : 0
|
74
|
+
stamps = utils.find_notes(patterns, repo, num_of_notes)
|
75
|
+
|
72
76
|
output = []
|
73
77
|
if @opts[:verbose]
|
74
78
|
collect_timestamps_by_date(stamps).each { |date, timestamps|
|
@@ -106,23 +110,6 @@ OPTIONS:
|
|
106
110
|
-v, --verbose
|
107
111
|
-w, --week
|
108
112
|
|
109
|
-
STAMP_PATTERN must be:
|
110
|
-
|
111
|
-
(a) full qualified timestamp (with suffix): "20201030160200"
|
112
|
-
(b) year and date part: "20201030"
|
113
|
-
(c) year and month part: "202010"
|
114
|
-
(d) year part only: "2020"
|
115
|
-
(e) date part only: "1030"
|
116
|
-
|
117
|
-
KEYWORD:
|
118
|
-
|
119
|
-
- "today" (or "to")
|
120
|
-
- "yeasterday" (or "ye")
|
121
|
-
- "this_week" (or "tw")
|
122
|
-
- "last_week" (or "lw")
|
123
|
-
- "this_month" (or "tm")
|
124
|
-
- "last_month" (or "lm")
|
125
|
-
|
126
113
|
An option "--verbose" is acceptable. It specifies to counts number of
|
127
114
|
notes by each day, then put it with the date before notes. It looks
|
128
115
|
like as follows:
|
@@ -140,11 +127,35 @@ days of a week. Typically, the option is used with a STAMP_PATTERN
|
|
140
127
|
which specifies a date, such "20201117", then it enumerates all days
|
141
128
|
of the week which contains "17th November 2020".
|
142
129
|
|
130
|
+
STAMP_PATTERN must be:
|
131
|
+
|
132
|
+
(a) full qualified timestamp (with suffix): "20201030160200"
|
133
|
+
(b) year and date part: "20201030"
|
134
|
+
(c) year and month part: "202010"
|
135
|
+
(d) year part only: "2020"
|
136
|
+
(e) date part only: "1030"
|
137
|
+
|
143
138
|
A STAMP_PATTERN other than (a) and (b) causes an error if it was used
|
144
139
|
with "--week" option.
|
145
140
|
|
146
141
|
When no STAMP_PATTERN was specified with "--week" option, the output
|
147
142
|
would be as same as the KEYWORD, "this_week" was specified.
|
143
|
+
|
144
|
+
KEYWORD:
|
145
|
+
|
146
|
+
- "today" (or "to")
|
147
|
+
- "yeasterday" (or "ye")
|
148
|
+
- "this_week" (or "tw")
|
149
|
+
- "last_week" (or "lw")
|
150
|
+
- "this_month" (or "tm")
|
151
|
+
- "last_month" (or "lm")
|
152
|
+
- "recent" (or "re")
|
153
|
+
- "all"
|
154
|
+
|
155
|
+
The keyword, "recent" specifies to enumerate recent notes in the
|
156
|
+
repository. The keyword, "all" specifies to enumerate all notes in
|
157
|
+
the repository.
|
158
|
+
|
148
159
|
HELP
|
149
160
|
end
|
150
161
|
|
@@ -25,7 +25,8 @@ module Rbnotes::Commands
|
|
25
25
|
|
26
26
|
repo = Textrepo.init(conf)
|
27
27
|
|
28
|
-
|
28
|
+
num_of_notes = utils.specified_recent?(args) ? conf[:number_of_recent_notes] : 0
|
29
|
+
stamps = utils.find_notes(patterns, repo, num_of_notes)
|
29
30
|
return if stamps.empty?
|
30
31
|
|
31
32
|
list = []
|
@@ -29,6 +29,9 @@ module Rbnotes::Commands
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def execute(args, conf)
|
32
|
+
@opts = {}
|
33
|
+
parse_opts(args)
|
34
|
+
|
32
35
|
pattern = args.shift
|
33
36
|
raise MissingArgumentError, args if pattern.nil?
|
34
37
|
|
@@ -46,11 +49,18 @@ module Rbnotes::Commands
|
|
46
49
|
def help # :nodoc:
|
47
50
|
puts <<HELP
|
48
51
|
usage:
|
49
|
-
#{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
|
52
|
+
#{Rbnotes::NAME} search [OPTIONS] PATTERN [STAMP_PATTERN]
|
50
53
|
|
51
54
|
PATTERN is a word (or words) to search, it may also be a regular
|
52
55
|
expression.
|
53
56
|
|
57
|
+
OPTIONS:
|
58
|
+
-s, --subject-only
|
59
|
+
|
60
|
+
An option "--subject-only" is acceptable. It specifies to search in
|
61
|
+
only the subject of each note. The subject means the first line of
|
62
|
+
the note text.
|
63
|
+
|
54
64
|
STAMP_PATTERN must be:
|
55
65
|
|
56
66
|
(a) full qualified timestamp (with suffix): "20201030160200"
|
@@ -58,11 +68,25 @@ STAMP_PATTERN must be:
|
|
58
68
|
(c) year and month part: "202010"
|
59
69
|
(d) year part only: "2020"
|
60
70
|
(e) date part only: "1030"
|
71
|
+
|
61
72
|
HELP
|
62
73
|
end
|
63
74
|
|
64
75
|
private
|
65
76
|
|
77
|
+
def parse_opts(args)
|
78
|
+
while args.size > 0
|
79
|
+
arg = args.shift
|
80
|
+
case arg
|
81
|
+
when "-s", "--subject-only"
|
82
|
+
@opts[:subject_only] = true
|
83
|
+
else
|
84
|
+
args.unshift(arg)
|
85
|
+
break
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
66
90
|
# Each entry of search result is:
|
67
91
|
#
|
68
92
|
# [<timestamp>, <line_number>, <matched_text>]
|
@@ -84,6 +108,10 @@ HELP
|
|
84
108
|
}
|
85
109
|
|
86
110
|
def print_search_result(entries)
|
111
|
+
if @opts[:subject_only]
|
112
|
+
entries.select!{|e| e.line_number == 1}
|
113
|
+
end
|
114
|
+
|
87
115
|
maxcol_stamp = entries.map(&:timestamp_size).max
|
88
116
|
maxcol_num = entries.map(&:line_number_digits_size).max
|
89
117
|
|
@@ -91,7 +119,11 @@ HELP
|
|
91
119
|
stamp_display = "%- *s" % [maxcol_stamp, e.timestamp]
|
92
120
|
num_display = "%*d" % [maxcol_num, e.line_number]
|
93
121
|
|
94
|
-
|
122
|
+
if @opts[:subject_only]
|
123
|
+
puts "#{stamp_display}: #{e.matched_text}"
|
124
|
+
else
|
125
|
+
puts "#{stamp_display}: #{num_display}: #{e.matched_text}"
|
126
|
+
end
|
95
127
|
}
|
96
128
|
end
|
97
129
|
|
@@ -22,7 +22,7 @@ module Rbnotes::Commands
|
|
22
22
|
parse_opts(args)
|
23
23
|
|
24
24
|
repo = Textrepo.init(conf)
|
25
|
-
stamps = read_timestamps(args, repo)
|
25
|
+
stamps = read_timestamps(args, repo, conf)
|
26
26
|
return if stamps.empty?
|
27
27
|
|
28
28
|
content = stamps.map { |stamp|
|
@@ -98,13 +98,14 @@ HELP
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
def read_timestamps(args, repo)
|
101
|
+
def read_timestamps(args, repo, conf)
|
102
102
|
utils = Rbnotes.utils
|
103
103
|
if args.empty?
|
104
104
|
stamps = utils.read_multiple_timestamps(args)
|
105
105
|
else
|
106
106
|
patterns = utils.read_timestamp_patterns(args)
|
107
|
-
|
107
|
+
num_of_notes = utils.specified_recent?(args) ? conf[:number_of_recent_notes] : 0
|
108
|
+
stamps = utils.find_notes(patterns, repo, num_of_notes)
|
108
109
|
end
|
109
110
|
stamps
|
110
111
|
end
|
data/lib/rbnotes/conf.rb
CHANGED
@@ -31,6 +31,12 @@ module Rbnotes
|
|
31
31
|
|
32
32
|
DIRNAME_COMMON_CONF = ".config"
|
33
33
|
|
34
|
+
##
|
35
|
+
# Name of the number of notes to enumerate. The values is
|
36
|
+
# referred only to enumerate the recent notes.
|
37
|
+
|
38
|
+
NUMBER_OF_RECENT_NOTES = 10
|
39
|
+
|
34
40
|
def initialize(path = nil) # :nodoc:
|
35
41
|
@conf = {}
|
36
42
|
|
@@ -90,6 +96,7 @@ module Rbnotes
|
|
90
96
|
:repository_type => :file_system,
|
91
97
|
:repository_name => "notes",
|
92
98
|
:repository_base => "~",
|
99
|
+
:number_of_recent_notes => 10,
|
93
100
|
}
|
94
101
|
|
95
102
|
MODE_POSTFIX = {
|
data/lib/rbnotes/utils.rb
CHANGED
@@ -125,6 +125,8 @@ module Rbnotes
|
|
125
125
|
# read_timestamp(args) -> String
|
126
126
|
|
127
127
|
def read_timestamp(args)
|
128
|
+
args = args.dup
|
129
|
+
|
128
130
|
str = args.shift || read_arg($stdin)
|
129
131
|
raise NoArgumentError if str.nil?
|
130
132
|
|
@@ -163,6 +165,9 @@ module Rbnotes
|
|
163
165
|
# Commands::Pick#execute.
|
164
166
|
#
|
165
167
|
def read_timestamp_patterns(args, enum_week: false)
|
168
|
+
args = args.dup
|
169
|
+
|
170
|
+
validate_arguments(args)
|
166
171
|
patterns = nil
|
167
172
|
if enum_week
|
168
173
|
args.unshift(Time.now.strftime("%Y%m%d")) if args.size == 0
|
@@ -254,12 +259,13 @@ module Rbnotes
|
|
254
259
|
# expand_keyword_in_args(Array of Strings) -> Array of Strings
|
255
260
|
#
|
256
261
|
def expand_keyword_in_args(args)
|
262
|
+
args = args.dup
|
257
263
|
patterns = []
|
258
264
|
while args.size > 0
|
259
265
|
arg = args.shift
|
260
|
-
if arg == "all"
|
266
|
+
if arg == "all" or arg == "recent" or arg == "re"
|
261
267
|
return [nil]
|
262
|
-
elsif
|
268
|
+
elsif valid_keyword?(arg)
|
263
269
|
patterns.concat(expand_keyword(arg))
|
264
270
|
else
|
265
271
|
patterns << arg
|
@@ -304,13 +310,27 @@ module Rbnotes
|
|
304
310
|
# given repository. Returns an Array contains Timestamp objects.
|
305
311
|
# The returned Array is sorted by Timestamp.
|
306
312
|
#
|
313
|
+
# When a positive number was specified as the 3rd argument, the
|
314
|
+
# number was used as the limitation count of enumerated notes.
|
315
|
+
#
|
307
316
|
# :call-seq:
|
308
|
-
# find_notes(Array of timestamp patterns, Textrepo::Repository)
|
317
|
+
# find_notes(Array of timestamp patterns, Textrepo::Repository, Integer)
|
309
318
|
|
310
|
-
def find_notes(timestamp_patterns, repo)
|
311
|
-
timestamp_patterns.map { |pat|
|
319
|
+
def find_notes(timestamp_patterns, repo, num_of_notes = 0)
|
320
|
+
notes = timestamp_patterns.map { |pat|
|
312
321
|
repo.entries(pat)
|
313
322
|
}.flatten.sort{ |a, b| b <=> a }.uniq
|
323
|
+
|
324
|
+
if num_of_notes > 0
|
325
|
+
notes[0,num_of_notes]
|
326
|
+
else
|
327
|
+
notes
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def specified_recent?(args)
|
332
|
+
validate_arguments(args)
|
333
|
+
args.include?("recent") or args.include?("re")
|
314
334
|
end
|
315
335
|
|
316
336
|
# :stopdoc:
|
@@ -360,6 +380,30 @@ module Rbnotes
|
|
360
380
|
str
|
361
381
|
end
|
362
382
|
|
383
|
+
##
|
384
|
+
# Validates arguments as timestamp strings or keywords. If all
|
385
|
+
# arguments are valid as timestamp strings or keywords, do
|
386
|
+
# nothing. Otherwise, raise an error.
|
387
|
+
#
|
388
|
+
# :call-seq:
|
389
|
+
# validate_arguments(an array of strings) -> nil
|
390
|
+
#
|
391
|
+
def validate_arguments(args)
|
392
|
+
args.each { |arg|
|
393
|
+
unless valid_keyword?(arg) or valid_timestamp_pattern?(arg)
|
394
|
+
raise InvalidTimestampPatternError, arg
|
395
|
+
end
|
396
|
+
}
|
397
|
+
end
|
398
|
+
|
399
|
+
def valid_keyword?(arg)
|
400
|
+
KEYWORDS.include?(arg)
|
401
|
+
end
|
402
|
+
|
403
|
+
def valid_timestamp_pattern?(arg)
|
404
|
+
!/[^_\d]/.match(arg)
|
405
|
+
end
|
406
|
+
|
363
407
|
##
|
364
408
|
# Expands a keyword to timestamp strings.
|
365
409
|
#
|
@@ -388,6 +432,8 @@ module Rbnotes
|
|
388
432
|
end
|
389
433
|
|
390
434
|
KEYWORDS = %w(
|
435
|
+
all
|
436
|
+
recent re
|
391
437
|
today to yesterday ye
|
392
438
|
this_week tw last_week lw
|
393
439
|
this_month tm last_month lm
|
data/lib/rbnotes/version.rb
CHANGED
data/rbnotes.gemspec
CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_dependency "textrepo", "~> 0.5.
|
29
|
-
spec.add_dependency "unicode-display_width", "~> 1.
|
28
|
+
spec.add_dependency "textrepo", "~> 0.5.9"
|
29
|
+
spec.add_dependency "unicode-display_width", "~> 1.8"
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbnotes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: textrepo
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5.
|
19
|
+
version: 0.5.9
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5.
|
26
|
+
version: 0.5.9
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: unicode-display_width
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.8'
|
41
41
|
description: Rbnotes allows you to write a note into a single repository.
|
42
42
|
email:
|
43
43
|
- mnbi@users.noreply.github.com
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.3.11
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: A simple utility to write a note.
|