rbnotes 0.4.0 → 0.4.5
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 +4 -4
- data/CHANGELOG.md +40 -9
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -4
- data/README.md +37 -0
- data/exe/rbnotes +10 -1
- data/lib/rbnotes.rb +2 -0
- data/lib/rbnotes/commands.rb +158 -39
- data/lib/rbnotes/commands/add.rb +92 -9
- data/lib/rbnotes/commands/delete.rb +24 -12
- data/lib/rbnotes/commands/export.rb +58 -0
- data/lib/rbnotes/commands/help.rb +98 -0
- data/lib/rbnotes/commands/import.rb +39 -2
- data/lib/rbnotes/commands/list.rb +102 -11
- data/lib/rbnotes/commands/search.rb +48 -27
- data/lib/rbnotes/commands/show.rb +33 -2
- data/lib/rbnotes/commands/update.rb +56 -17
- data/lib/rbnotes/version.rb +2 -2
- data/rbnotes.gemspec +1 -1
- metadata +6 -4
@@ -1,30 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
##
|
4
|
-
# Searches a given pattern in notes those have timestamps match a
|
5
|
-
# given timestamp pattern. The first argument is a pattern to search.
|
6
|
-
# It is a String object represents a portion of text or it may a
|
7
|
-
# String represents a regular expression. The second argument is
|
8
|
-
# optional and it is a timestamp pattern to specify the search target.
|
9
|
-
#
|
10
|
-
# A pattern for search is mandatory. If no pattern, raises
|
11
|
-
# Rbnotes::MissingArgumentError.
|
12
|
-
#
|
13
|
-
# Example of PATTERN:
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
1
|
+
module Rbnotes::Commands
|
2
|
+
|
3
|
+
##
|
4
|
+
# Searches a given pattern in notes those have timestamps match a
|
5
|
+
# given timestamp pattern. The first argument is a pattern to search.
|
6
|
+
# It is a String object represents a portion of text or it may a
|
7
|
+
# String represents a regular expression. The second argument is
|
8
|
+
# optional and it is a timestamp pattern to specify the search target.
|
9
|
+
#
|
10
|
+
# A pattern for search is mandatory. If no pattern, raises
|
11
|
+
# Rbnotes::MissingArgumentError.
|
12
|
+
#
|
13
|
+
# Example of PATTERN for search:
|
14
|
+
#
|
15
|
+
# "rbnotes" (a word)
|
16
|
+
# "macOS Big Sur" (a few words)
|
17
|
+
# "2[0-9]{3}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" (a regular expression)
|
18
|
+
#
|
19
|
+
# A timestamp pattern is optional. If no timestamp pattern, all notes
|
20
|
+
# in the repository would be target of search.
|
21
|
+
#
|
22
|
+
# See the document of `Rbnotes::Commands::List#execute` to know about
|
23
|
+
# a timestamp pattern.
|
24
|
+
|
25
|
+
class Search < Command
|
26
|
+
|
27
|
+
def description # :nodoc:
|
28
|
+
"Search a given pattern in notes"
|
29
|
+
end
|
30
|
+
|
28
31
|
def execute(args, conf)
|
29
32
|
pattern = args.shift
|
30
33
|
raise MissingArgumentError, args if pattern.nil?
|
@@ -42,5 +45,23 @@ module Rbnotes
|
|
42
45
|
}
|
43
46
|
end
|
44
47
|
end
|
48
|
+
|
49
|
+
def help # :nodoc:
|
50
|
+
puts <<HELP
|
51
|
+
usage:
|
52
|
+
#{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
|
53
|
+
|
54
|
+
PATTERN is a word (or words) to search, it may also be a regular
|
55
|
+
expression.
|
56
|
+
|
57
|
+
STAMP_PATTERN must be:
|
58
|
+
|
59
|
+
(a) full qualified timestamp (with suffix): "20201030160200"
|
60
|
+
(b) year and date part: "20201030"
|
61
|
+
(c) year and month part: "202010"
|
62
|
+
(d) year part only: "2020"
|
63
|
+
(e) date part only: "1030"
|
64
|
+
HELP
|
65
|
+
end
|
45
66
|
end
|
46
67
|
end
|
@@ -1,5 +1,23 @@
|
|
1
|
-
module Rbnotes
|
2
|
-
|
1
|
+
module Rbnotes::Commands
|
2
|
+
|
3
|
+
##
|
4
|
+
# Shows the content of the note specified by the argument. The
|
5
|
+
# argument must be a string which can be converted into
|
6
|
+
# Textrepo::Timestamp object.
|
7
|
+
#
|
8
|
+
# A string for Timestamp must be:
|
9
|
+
#
|
10
|
+
# "20201106112600" : year, date, time and sec
|
11
|
+
# "20201106112600_012" : with suffix
|
12
|
+
#
|
13
|
+
# If no argument is passed, reads the standard input for an argument.
|
14
|
+
|
15
|
+
class Show < Command
|
16
|
+
|
17
|
+
def description # :nodoc:
|
18
|
+
"Show the content of a note"
|
19
|
+
end
|
20
|
+
|
3
21
|
def execute(args, conf)
|
4
22
|
stamp = Rbnotes::Utils.read_timestamp(args)
|
5
23
|
|
@@ -17,5 +35,18 @@ module Rbnotes
|
|
17
35
|
puts content
|
18
36
|
end
|
19
37
|
end
|
38
|
+
|
39
|
+
def help # :nodoc:
|
40
|
+
puts <<HELP
|
41
|
+
usage:
|
42
|
+
#{Rbnotes::NAME} show [TIMESTAMP]
|
43
|
+
|
44
|
+
Show the content of given note. TIMESTAMP must be a fully qualified
|
45
|
+
one, such "20201016165130" or "20201016165130_012" if it has a suffix.
|
46
|
+
|
47
|
+
The command try to read its argument from the standard input when no
|
48
|
+
argument was passed in the command line.
|
49
|
+
HELP
|
50
|
+
end
|
20
51
|
end
|
21
52
|
end
|
@@ -1,37 +1,49 @@
|
|
1
1
|
module Rbnotes::Commands
|
2
|
+
|
2
3
|
##
|
3
4
|
# Updates the content of the note associated with given timestamp.
|
4
|
-
#
|
5
|
+
#
|
6
|
+
# Reads its argument from the standard input when no argument was
|
7
|
+
# passed in the command line.
|
8
|
+
#
|
5
9
|
# The timestamp associated with the note will be updated to new one,
|
6
10
|
# which is generated while the command exection.
|
7
11
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# repository. When the given timestamp was not found, the command
|
11
|
-
# fails.
|
12
|
-
#
|
13
|
-
# Timestamp which is associated to the target note will be newly
|
14
|
-
# generated with the command execution time. That is, the timestamp
|
15
|
-
# before the command exection will be obsolete.
|
12
|
+
# When "-k" (or "--keep") option is specified, the timestamp will
|
13
|
+
# remain unchanged.
|
16
14
|
#
|
17
|
-
#
|
18
|
-
# content of the note. The editor program will be searched as same
|
19
|
-
# as add command.
|
15
|
+
# Actual modification is done interactively by the external editor.
|
20
16
|
#
|
21
|
-
#
|
17
|
+
# The editor program will be searched as same as add command. If
|
18
|
+
# none of editors is available, the execution fails.
|
22
19
|
|
23
20
|
class Update < Command
|
24
21
|
include ::Rbnotes::Utils
|
25
22
|
|
23
|
+
def description # :nodoc:
|
24
|
+
"Update the content of a note"
|
25
|
+
end
|
26
|
+
|
26
27
|
##
|
27
28
|
# The 1st and only one argument is the timestamp to speficy the
|
28
|
-
# note to update.
|
29
|
-
# to the note updated.
|
29
|
+
# note to update.
|
30
30
|
#
|
31
31
|
# :call-seq:
|
32
32
|
# "20201020112233" -> "20201021123400"
|
33
33
|
|
34
34
|
def execute(args, conf)
|
35
|
+
@opts = {}
|
36
|
+
while args.size > 0
|
37
|
+
arg = args.shift
|
38
|
+
case arg
|
39
|
+
when "-k", "--keep"
|
40
|
+
@opts[:keep_timestamp] = true
|
41
|
+
else
|
42
|
+
args.unshift(arg)
|
43
|
+
break
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
35
47
|
target_stamp = Rbnotes::Utils.read_timestamp(args)
|
36
48
|
editor = find_editor(conf[:editor])
|
37
49
|
repo = Textrepo.init(conf)
|
@@ -47,13 +59,18 @@ module Rbnotes::Commands
|
|
47
59
|
text = File.readlines(tmpfile, :chomp => true)
|
48
60
|
|
49
61
|
unless text.empty?
|
62
|
+
keep = @opts[:keep_timestamp] || false
|
50
63
|
newstamp = nil
|
51
64
|
begin
|
52
|
-
newstamp = repo.update(target_stamp, text)
|
65
|
+
newstamp = repo.update(target_stamp, text, keep)
|
53
66
|
rescue StandardError => e
|
54
67
|
puts e.message
|
55
68
|
else
|
56
|
-
|
69
|
+
if keep
|
70
|
+
puts "Update the note content, the timestamp unchanged [%s]" % newstamp
|
71
|
+
else
|
72
|
+
puts "Update the note [%s -> %s]" % [target_stamp, newstamp] unless target_stamp == newstamp
|
73
|
+
end
|
57
74
|
ensure
|
58
75
|
# Don't forget to remove the temporary file.
|
59
76
|
File.delete(tmpfile)
|
@@ -62,5 +79,27 @@ module Rbnotes::Commands
|
|
62
79
|
puts "Nothing is updated, since the specified content is empty."
|
63
80
|
end
|
64
81
|
end
|
82
|
+
|
83
|
+
def help # :nodoc:
|
84
|
+
puts <<HELP
|
85
|
+
usage:
|
86
|
+
#{Rbnotes::NAME} update [TIMESTAMP]
|
87
|
+
|
88
|
+
Updates the content of the note associated with given timestamp.
|
89
|
+
|
90
|
+
Reads its argument from the standard input when no argument was passed
|
91
|
+
in the command line.
|
92
|
+
|
93
|
+
The timestamp associated with the note will be updated to new one,
|
94
|
+
which is generated while the command exection.
|
95
|
+
|
96
|
+
When "-k" (or "--keep") option is specified, the timestamp will remain
|
97
|
+
unchanged.
|
98
|
+
|
99
|
+
Actual modification is done interactively by the external editor. The
|
100
|
+
editor program will be searched as same as add command. If none of
|
101
|
+
editors is available, the execution fails.
|
102
|
+
HELP
|
103
|
+
end
|
65
104
|
end
|
66
105
|
end
|
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"
|
28
|
+
spec.add_dependency "textrepo", "~> 0.5.4"
|
29
29
|
spec.add_dependency "unicode-display_width", "~> 1.7"
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: textrepo
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.5.4
|
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:
|
26
|
+
version: 0.5.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: unicode-display_width
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- lib/rbnotes/commands.rb
|
65
65
|
- lib/rbnotes/commands/add.rb
|
66
66
|
- lib/rbnotes/commands/delete.rb
|
67
|
+
- lib/rbnotes/commands/export.rb
|
68
|
+
- lib/rbnotes/commands/help.rb
|
67
69
|
- lib/rbnotes/commands/import.rb
|
68
70
|
- lib/rbnotes/commands/list.rb
|
69
71
|
- lib/rbnotes/commands/search.rb
|