rbnotes 0.4.1 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -10
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -4
- data/README.md +4 -4
- data/conf/config.yml +1 -0
- data/conf/config_deve.yml +1 -0
- data/exe/rbnotes +10 -1
- data/lib/rbnotes.rb +8 -0
- data/lib/rbnotes/commands.rb +161 -59
- data/lib/rbnotes/commands/add.rb +43 -3
- data/lib/rbnotes/commands/delete.rb +25 -13
- 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 +47 -56
- data/lib/rbnotes/commands/pick.rb +47 -0
- data/lib/rbnotes/commands/search.rb +25 -2
- data/lib/rbnotes/commands/show.rb +34 -3
- data/lib/rbnotes/commands/update.rb +59 -21
- data/lib/rbnotes/error.rb +11 -0
- data/lib/rbnotes/utils.rb +174 -8
- data/lib/rbnotes/version.rb +2 -2
- data/rbnotes.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8c8badba84cecd738d81b16ec9539c6b8f51199433da1808bcf07fffd45635c
|
4
|
+
data.tar.gz: ab85b5e5d963b88014ffeb780c8da1beb2116e55789e13dfcd2fdea3183651e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bcbd5ce75daf93183480fe1f00ab72d801b70c894bb9ba70ecc8f03cc7cdc3f2173c71dc0a7c6d119cfcbb9a0c63dff5b8c05a527c1df8dfbbe186509a4e41c
|
7
|
+
data.tar.gz: 72a593af5a18ce7482952df1ceb9d2eb6132d2072bb3adc70075b08118e0594d0f294738e74ddf0087adb2a06946f145cef4ff71b4425aeb855aeaf68e211ac9
|
data/CHANGELOG.md
CHANGED
@@ -7,8 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
## [Unreleased]
|
8
8
|
Nothing to record here.
|
9
9
|
|
10
|
-
## [0.4.
|
10
|
+
## [0.4.6] - 2020-11-13
|
11
|
+
### Added
|
12
|
+
- Add a new command `pick` to select a note with picker program. (#59)
|
13
|
+
|
14
|
+
## [0.4.5] - 2020-11-12
|
15
|
+
### Changed
|
16
|
+
- Add a feature to accept multiple args for `list`. (#57)
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
- Fix issue #54: Notes list does not sort correctly.
|
20
|
+
|
21
|
+
## [0.4.4] - 2020-11-09
|
22
|
+
### Changed
|
23
|
+
- Add a feature to use a keyword as an argument for `list`. (#47)
|
24
|
+
|
25
|
+
## [0.4.3] - 2020-11-08
|
11
26
|
### Added
|
27
|
+
- Add a new command `export` to write out a note into a file. (#51)
|
28
|
+
- Add individual help for each command. (#42)
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
- Fix `add` fails without modification (#48)
|
32
|
+
|
33
|
+
## [0.4.2] - 2020-11-05
|
34
|
+
### Changed
|
35
|
+
- Add a feature to keep the timestamp in `update` command. (#44)
|
36
|
+
|
37
|
+
### Fixed
|
38
|
+
- Fix issue #45: hanging up of `add` command.
|
39
|
+
|
40
|
+
## [0.4.1] - 2020-11-04
|
41
|
+
### Changed
|
12
42
|
- Add a feature to accept a timestamp in `add` command. (#34)
|
13
43
|
|
14
44
|
## [0.4.0] - 2020-11-03
|
@@ -17,20 +47,21 @@ Nothing to record here.
|
|
17
47
|
|
18
48
|
## [0.3.1] - 2020-10-30
|
19
49
|
### Added
|
20
|
-
- Add feature to specify configuration file in the command
|
50
|
+
- Add a feature to specify configuration file in the command
|
51
|
+
line. (#21)
|
21
52
|
|
22
53
|
## [0.3.0] - 2020-10-29
|
23
|
-
###
|
54
|
+
### Changed
|
24
55
|
- Add feature to read argument from the standard input. (#27)
|
25
56
|
|
26
57
|
## [0.2.2] - 2020-10-27
|
27
|
-
###
|
28
|
-
- Add feature to accept a timestamp pattern in `list` command. (#22)
|
58
|
+
### Changed
|
59
|
+
- Add a feature to accept a timestamp pattern in `list` command. (#22)
|
29
60
|
|
30
61
|
## [0.2.1] - 2020-10-25
|
31
62
|
### Added
|
32
|
-
- Add feature to load the configuration from an external file.
|
33
|
-
- Add description about the configuration file in README.md
|
63
|
+
- Add a feature to load the configuration from an external file.
|
64
|
+
- Add a description about the configuration file in README.md.
|
34
65
|
|
35
66
|
## [0.2.0] - 2020-10-23
|
36
67
|
### Added
|
@@ -40,15 +71,15 @@ Nothing to record here.
|
|
40
71
|
- Add a new task into `Rakefile` to generate RI docs.
|
41
72
|
- The intention of the task is to verify RI docs.
|
42
73
|
|
43
|
-
###
|
74
|
+
### Changed
|
44
75
|
- Refactor some tests.
|
45
76
|
|
46
77
|
## [0.1.3] - 2020-10-15
|
47
|
-
###
|
78
|
+
### Changed
|
48
79
|
- Add help text for the `conf` command.
|
49
80
|
|
50
81
|
## [0.1.2] - 2020-10-15
|
51
|
-
###
|
82
|
+
### Changed
|
52
83
|
- Adapt the API change in `textrepo` (0.4.0).
|
53
84
|
|
54
85
|
## [0.1.0] - 2020-10-12
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbnotes (0.4.
|
5
|
-
textrepo (~> 0.5)
|
4
|
+
rbnotes (0.4.6)
|
5
|
+
textrepo (~> 0.5.4)
|
6
6
|
unicode-display_width (~> 1.7)
|
7
7
|
|
8
8
|
GEM
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
minitest (5.14.2)
|
12
12
|
rake (13.0.1)
|
13
|
-
textrepo (0.5.
|
13
|
+
textrepo (0.5.6)
|
14
14
|
unicode-display_width (1.7.0)
|
15
15
|
|
16
16
|
PLATFORMS
|
@@ -20,7 +20,7 @@ DEPENDENCIES
|
|
20
20
|
minitest (~> 5.0)
|
21
21
|
rake (~> 13.0)
|
22
22
|
rbnotes!
|
23
|
-
textrepo (~> 0.5)
|
23
|
+
textrepo (~> 0.5.4)
|
24
24
|
|
25
25
|
BUNDLED WITH
|
26
26
|
2.1.4
|
data/README.md
CHANGED
@@ -164,10 +164,10 @@ don't have to set `:searcher_options` for them.
|
|
164
164
|
|
165
165
|
| searcher | default options in `textrepo` |
|
166
166
|
|:---------|:---------------------------------------------------|
|
167
|
-
| `grep` | `["-i", "-n", "-R", "-E"]`
|
168
|
-
| `egrep` | `["-i", "-n", "-R"]`
|
169
|
-
| `ggrep` | `["-i", "-n", "-R", "-E"]`
|
170
|
-
| `gegrep` | `["-i", "-n", "-R"]`
|
167
|
+
| `grep` | `["-i", "-n", "-H", "-R", "-E"]` |
|
168
|
+
| `egrep` | `["-i", "-n", "-H", "-R"]` |
|
169
|
+
| `ggrep` | `["-i", "-n", "-H", "-R", "-E"]` |
|
170
|
+
| `gegrep` | `["-i", "-n", "-H", "-R"]` |
|
171
171
|
| `rg` | `["-S", "-n", "--no-heading", "--color", "never"]` |
|
172
172
|
|
173
173
|
Those searcher names are used in macOS (with Homebrew). Any other OS
|
data/conf/config.yml
CHANGED
data/conf/config_deve.yml
CHANGED
data/exe/rbnotes
CHANGED
@@ -23,6 +23,14 @@ class App
|
|
23
23
|
file = File.expand_path(file)
|
24
24
|
raise ArgumentError, "no such file: %s" % file unless FileTest.exist?(file)
|
25
25
|
@gopts[:conf_file] = file
|
26
|
+
when "-v", "--version"
|
27
|
+
args.clear
|
28
|
+
args.unshift("version")
|
29
|
+
break
|
30
|
+
when "-h", "--help"
|
31
|
+
args.clear
|
32
|
+
args.unshift("help")
|
33
|
+
break
|
26
34
|
else
|
27
35
|
args.unshift(arg)
|
28
36
|
break
|
@@ -43,7 +51,8 @@ begin
|
|
43
51
|
rescue MissingArgumentError, MissingTimestampError,
|
44
52
|
NoEditorError, ProgramAbortError,
|
45
53
|
Textrepo::InvalidTimestampStringError,
|
46
|
-
ArgumentError
|
54
|
+
ArgumentError,
|
55
|
+
Errno::EACCES => e
|
47
56
|
puts e.message
|
48
57
|
exit 1
|
49
58
|
end
|
data/lib/rbnotes.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require "textrepo"
|
2
2
|
|
3
3
|
module Rbnotes
|
4
|
+
NAME = File.basename($PROGRAM_NAME) # :nodoc:
|
5
|
+
|
4
6
|
require_relative "rbnotes/version"
|
5
7
|
require_relative "rbnotes/error"
|
6
8
|
require_relative "rbnotes/conf"
|
7
9
|
require_relative "rbnotes/utils"
|
8
10
|
require_relative "rbnotes/commands"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def utils
|
14
|
+
Utils.instance
|
15
|
+
end
|
16
|
+
end
|
9
17
|
end
|
data/lib/rbnotes/commands.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
module Rbnotes
|
2
|
+
|
2
3
|
##
|
3
4
|
# This module defines all command classes of rbnotes. Each command
|
4
5
|
# class must be derived from Rbnotes::Commands::Command class.
|
5
6
|
|
6
7
|
module Commands
|
8
|
+
|
7
9
|
##
|
8
10
|
# The base class for a command class.
|
9
11
|
|
10
12
|
class Command
|
11
13
|
|
14
|
+
##
|
15
|
+
# Short description of each command.
|
16
|
+
|
17
|
+
def description; nil; end
|
18
|
+
|
12
19
|
##
|
13
20
|
# :call-seq:
|
14
21
|
# execute(Array, Hash) -> nil
|
@@ -17,8 +24,17 @@ module Rbnotes
|
|
17
24
|
# - Hash : rbnotes configuration
|
18
25
|
|
19
26
|
def execute(args, conf)
|
20
|
-
Builtins
|
27
|
+
Builtins.default_cmd.new.execute(args, conf)
|
21
28
|
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Shows the help message for the command.
|
32
|
+
#
|
33
|
+
|
34
|
+
def help
|
35
|
+
Builtins::Usage.new.execute(nil, nil)
|
36
|
+
end
|
37
|
+
|
22
38
|
end
|
23
39
|
|
24
40
|
# :stopdoc:
|
@@ -29,71 +45,73 @@ module Rbnotes
|
|
29
45
|
# - stamp: converts given TIME_STR into a timestamp.
|
30
46
|
# - time: converts given STAMP into a time string.
|
31
47
|
module Builtins
|
32
|
-
class
|
33
|
-
def execute(_, _)
|
34
|
-
puts <<USAGE
|
35
|
-
usage:
|
36
|
-
rbnotes [-c|--conf CONF_FILE] [command] [args]
|
37
|
-
|
38
|
-
option:
|
39
|
-
-c, --conf [CONF_FILE] : specifiy the configuration file
|
40
|
-
|
41
|
-
CONF_FILE must be written in YAML. To know about details of the
|
42
|
-
configuration file, see README.md or Wiki page.
|
43
|
-
|
44
|
-
command:
|
45
|
-
add : create a new note
|
46
|
-
import FILE : import a FILE into the repository
|
48
|
+
class Usage < Command
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
STAMP_PATTERN must be:
|
52
|
-
|
53
|
-
(a) full qualified timestamp (with suffix): "20201030160200"
|
54
|
-
(b) year and date part: "20201030"
|
55
|
-
(c) year and month part: "202010"
|
56
|
-
(d) year part only: "2020"
|
57
|
-
(e) date part only: "1030"
|
58
|
-
|
59
|
-
PATTERN is a word (or words) to search, it may also be a regular
|
60
|
-
expression.
|
61
|
-
|
62
|
-
show [STAMP] : show the note specified with STAMP
|
63
|
-
update [STAMP] : edit the note with external editor
|
64
|
-
delete [STAMP] : delete the note specified with STAMP
|
65
|
-
|
66
|
-
STAMP must be a sequence of digits to represent year, date and
|
67
|
-
time (and suffix), such "20201030160200" or "20201030160200_012".
|
68
|
-
|
69
|
-
show/update/delete reads its argument from the standard input when
|
70
|
-
no argument was passed in the command line.
|
50
|
+
def description
|
51
|
+
"Print usage"
|
52
|
+
end
|
71
53
|
|
72
|
-
|
73
|
-
|
54
|
+
def execute(_, _)
|
55
|
+
puts <<USAGE
|
56
|
+
Syntax:
|
57
|
+
#{Rbnotes::NAME} [-c| --conf CONF_FILE] [command] [args]
|
58
|
+
|
59
|
+
Example usage:
|
60
|
+
#{Rbnotes::NAME} add [-t STAMP_PATTERN]
|
61
|
+
#{Rbnotes::NAME} delete [TIMESTAMP]
|
62
|
+
#{Rbnotes::NAME} export [TIMESTAMP [FILENAME]]
|
63
|
+
#{Rbnotes::NAME} import FILE
|
64
|
+
#{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
|
65
|
+
#{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
|
66
|
+
#{Rbnotes::NAME} show [TIMESTAMP]
|
67
|
+
#{Rbnotes::NAME} update [TIMESTAMP]
|
68
|
+
|
69
|
+
Further help for each command:
|
70
|
+
#{Rbnotes::NAME} help commands
|
71
|
+
#{Rbnotes::NAME} help [COMMAND]
|
72
|
+
|
73
|
+
Further information:
|
74
|
+
https://github.com/mnbi/rbnotes/wiki
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
repo : print the repository path
|
78
|
-
stamp TIME_STR : convert TIME_STR into a timestamp
|
79
|
-
time STAMP : convert STAMP into a time string
|
76
|
+
USAGE
|
77
|
+
end
|
80
78
|
|
81
|
-
|
82
|
-
|
79
|
+
def help
|
80
|
+
puts <<HELP_USAGE
|
81
|
+
usage:
|
82
|
+
#{Rbnotes::NAME} usage
|
83
83
|
|
84
|
-
|
84
|
+
Print a short example of usage.
|
85
|
+
HELP_USAGE
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
class Version < Command
|
90
|
+
def description
|
91
|
+
"Print version"
|
92
|
+
end
|
93
|
+
|
89
94
|
def execute(_, _)
|
90
|
-
rbnotes_version = "
|
95
|
+
rbnotes_version = "#{Rbnotes::NAME} #{Rbnotes::VERSION} (#{Rbnotes::RELEASE})"
|
91
96
|
textrepo_version = "textrepo #{Textrepo::VERSION}"
|
92
97
|
puts "#{rbnotes_version} [#{textrepo_version}]"
|
93
98
|
end
|
99
|
+
|
100
|
+
def help
|
101
|
+
puts <<VERSION
|
102
|
+
usage:
|
103
|
+
#{Rbnotes::NAME} version
|
104
|
+
|
105
|
+
Print version of #{Rbnotes::NAME} and release date.
|
106
|
+
VERSION
|
107
|
+
end
|
94
108
|
end
|
95
109
|
|
96
110
|
class Repo < Command
|
111
|
+
def description
|
112
|
+
"Print repository path"
|
113
|
+
end
|
114
|
+
|
97
115
|
def execute(_, conf)
|
98
116
|
name = conf[:repository_name]
|
99
117
|
base = conf[:repository_base]
|
@@ -106,19 +124,49 @@ USAGE
|
|
106
124
|
File.join(base, name)
|
107
125
|
end
|
108
126
|
end
|
127
|
+
|
128
|
+
def help
|
129
|
+
puts <<REPO
|
130
|
+
usage:
|
131
|
+
#{Rbnotes::NAME} repo
|
132
|
+
|
133
|
+
Print the path of the repository. The type of the path entity depends
|
134
|
+
on what type is specified to the repository type in the configuration.
|
135
|
+
When ":file_system" is set to "repository_type", the path is a
|
136
|
+
directory which contains all note files. The structure of the
|
137
|
+
directory depends on the implementation of `textrepo`.
|
138
|
+
REPO
|
139
|
+
end
|
109
140
|
end
|
110
141
|
|
111
142
|
class Conf < Command
|
143
|
+
def description
|
144
|
+
"Print the current configuration"
|
145
|
+
end
|
146
|
+
|
112
147
|
def execute(_, conf)
|
113
148
|
conf.keys.sort.each { |k|
|
114
149
|
puts "#{k}=#{conf[k]}"
|
115
150
|
}
|
116
151
|
end
|
152
|
+
|
153
|
+
def help
|
154
|
+
puts <<CONF
|
155
|
+
usage:
|
156
|
+
#{Rbnotes::NAME} conf
|
157
|
+
|
158
|
+
Print the current configuration values.
|
159
|
+
CONF
|
160
|
+
end
|
117
161
|
end
|
118
162
|
|
119
163
|
require "time"
|
120
164
|
|
121
165
|
class Stamp < Command
|
166
|
+
def description
|
167
|
+
"Convert a time string into a timestamp string"
|
168
|
+
end
|
169
|
+
|
122
170
|
def execute(args, _)
|
123
171
|
time_str = args.shift
|
124
172
|
unless time_str.nil?
|
@@ -128,9 +176,30 @@ USAGE
|
|
128
176
|
super
|
129
177
|
end
|
130
178
|
end
|
179
|
+
|
180
|
+
def help
|
181
|
+
puts <<STAMP
|
182
|
+
usage:
|
183
|
+
#{Rbnotes::NAME} stamp
|
184
|
+
|
185
|
+
Convert a given time string into a timestamp string. The timestamp
|
186
|
+
string could be used as an argument of some rbnotes commands, such
|
187
|
+
"show". Here is short example of conversion:
|
188
|
+
|
189
|
+
"2020-11-06 16:51:15" -> "20201106165115"
|
190
|
+
"2020-11-06" -> "20201106000000"
|
191
|
+
"20201106" -> "20201106000000"
|
192
|
+
"2020-11-06 16" -> "20201106160000"
|
193
|
+
"2020-11-06 16:51" -> "20201106165100"
|
194
|
+
STAMP
|
195
|
+
end
|
131
196
|
end
|
132
197
|
|
133
198
|
class Time < Command
|
199
|
+
def description
|
200
|
+
"Convert a timestamp into a time string"
|
201
|
+
end
|
202
|
+
|
134
203
|
def execute(args, _)
|
135
204
|
stamp = args.shift
|
136
205
|
unless stamp.nil?
|
@@ -140,12 +209,41 @@ USAGE
|
|
140
209
|
super
|
141
210
|
end
|
142
211
|
end
|
212
|
+
|
213
|
+
def help
|
214
|
+
puts <<TIME
|
215
|
+
usage:
|
216
|
+
#{Rbnotes::NAME} time
|
217
|
+
|
218
|
+
Convert a given timestamp string into a time string. Here is short
|
219
|
+
example of conversion:
|
220
|
+
|
221
|
+
"20201106165115" -> "2020-11-06 16:51:15 +0900"
|
222
|
+
"202011061651" -> "2020-11-06 16:51:00 +0900"
|
223
|
+
"2020110616" -> "2020-11-06 16:00:00 +0900"
|
224
|
+
"20201106" -> "2020-11-06 00:00:00 +0900"
|
225
|
+
TIME
|
226
|
+
end
|
143
227
|
end
|
144
228
|
|
145
|
-
|
146
|
-
|
229
|
+
class << self
|
230
|
+
def default_cmd_name
|
231
|
+
"usage"
|
232
|
+
end
|
233
|
+
|
234
|
+
def default_cmd
|
235
|
+
Usage
|
236
|
+
end
|
147
237
|
|
148
|
-
|
238
|
+
def command(name)
|
239
|
+
begin
|
240
|
+
const_defined?(name, false) ? const_get(name, false) : nil
|
241
|
+
rescue NameError => _
|
242
|
+
nil
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
149
247
|
|
150
248
|
# :startdoc:
|
151
249
|
|
@@ -156,24 +254,28 @@ USAGE
|
|
156
254
|
# of the class.
|
157
255
|
#
|
158
256
|
# :call-seq:
|
257
|
+
# load("add") -> Rbnotes::Commands::Add
|
258
|
+
# load("delete") -> Rbnotes::Commands::Delete
|
259
|
+
# load("export") -> Rbnotes::Commands::Export
|
260
|
+
# load("help") -> Rbnotes::Commands::Help
|
159
261
|
# load("import") -> Rbnotes::Commnads::Import
|
160
262
|
# load("list") -> Rbnotes::Commands::List
|
263
|
+
# load("search") -> Rbnotes::Commands::Search
|
161
264
|
# load("show") -> Rbnotes::Commands::Show
|
265
|
+
# load("update") -> Rbnotes::Commands::Update
|
162
266
|
|
163
267
|
def load(cmd_name)
|
164
|
-
cmd_name ||=
|
268
|
+
cmd_name ||= Builtins.default_cmd_name
|
165
269
|
klass_name = cmd_name.capitalize
|
166
270
|
|
167
|
-
klass =
|
168
|
-
if
|
169
|
-
klass = Builtins::const_get(klass_name, false)
|
170
|
-
else
|
271
|
+
klass = Builtins.command(klass_name)
|
272
|
+
if klass.nil?
|
171
273
|
begin
|
172
274
|
require_relative "commands/#{cmd_name}"
|
173
275
|
klass = const_get(klass_name, false)
|
174
276
|
rescue LoadError => _
|
175
277
|
STDERR.puts "unknown command: #{cmd_name}"
|
176
|
-
klass = Builtins
|
278
|
+
klass = Builtins.default_cmd
|
177
279
|
end
|
178
280
|
end
|
179
281
|
klass.new
|