rbnotes 0.4.0 → 0.4.5

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: 87313e606a2e62b90b3e1c3f00ff46300f0e7a14e3b2fc8ffcad0abfda217646
4
- data.tar.gz: 95b8a57ca200b8a8460f61edfe0d796dcfec2f63cba4ec024294915f07752aa8
3
+ metadata.gz: 840d2acc4c93d5b03d833b6a518c9740518e025aeb3bb2b6751864d5cf9e9d1c
4
+ data.tar.gz: 759f8bdc29d64e32c73d7e02540603c3bdf84b6bdf3ac91b7a76bf8e3cf2005d
5
5
  SHA512:
6
- metadata.gz: 238f9140497e09ee4aedc331716c5725e61e00332255160d70844099e7f5d3f072f00edc3800e063f1f09e9e9c67669ca901c60c16c88a37e4594c07c9744238
7
- data.tar.gz: de00ee60c187517ec47f4601c572abc83f99dc3f4cde96c4db86e8cdda012eda5bdd5b1529fdf086f7f1858637720752bba8fa244d3e21f63d25456c56b7c71e
6
+ metadata.gz: b47f361e68f7e5275b981848035621fd31342a994d6bd5d90002f91417f4806ba364714b4ea86728f993e43e74868bf08508701531361c4e785830cc772a5b2e
7
+ data.tar.gz: '09cea0ff486e4e2a8521d732296e64a520c7d076088dd63c05cc4a9c219a2be28e65e50234859bab0d2772a92fb466b1ffc580525fb3565e8d68f7f7f81f8eec'
@@ -7,26 +7,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
+ ## [0.4.5] - 2020-11-12
11
+ ### Changed
12
+ - Add a feature to accept multiple args for `list`. (#57)
13
+
14
+ ### Fixed
15
+ - Fix issue #54: Notes list does not sort correctly.
16
+
17
+ ## [0.4.4] - 2020-11-09
18
+ ### Changed
19
+ - Add a feature to use a keyword as an argument for `list`. (#47)
20
+
21
+ ## [0.4.3] - 2020-11-08
22
+ ### Added
23
+ - Add a new command `export` to write out a note into a file. (#51)
24
+ - Add individual help for each command. (#42)
25
+
26
+ ### Fixed
27
+ - Fix `add` fails without modification (#48)
28
+
29
+ ## [0.4.2] - 2020-11-05
30
+ ### Changed
31
+ - Add a feature to keep the timestamp in `update` command. (#44)
32
+
33
+ ### Fixed
34
+ - Fix issue #45: hanging up of `add` command.
35
+
36
+ ## [0.4.1] - 2020-11-04
37
+ ### Changed
38
+ - Add a feature to accept a timestamp in `add` command. (#34)
39
+
10
40
  ## [0.4.0] - 2020-11-03
11
41
  ### Added
12
42
  - Add a new command `search` to perform full text search. (#33)
13
43
 
14
44
  ## [0.3.1] - 2020-10-30
15
45
  ### Added
16
- - Add feature to specify configuration file in the command line. (#21)
46
+ - Add a feature to specify configuration file in the command
47
+ line. (#21)
17
48
 
18
49
  ## [0.3.0] - 2020-10-29
19
- ### Added
50
+ ### Changed
20
51
  - Add feature to read argument from the standard input. (#27)
21
52
 
22
53
  ## [0.2.2] - 2020-10-27
23
- ### Added
24
- - Add feature to accept a timestamp pattern in `list` command. (#22)
54
+ ### Changed
55
+ - Add a feature to accept a timestamp pattern in `list` command. (#22)
25
56
 
26
57
  ## [0.2.1] - 2020-10-25
27
58
  ### Added
28
- - Add feature to load the configuration from an external file.
29
- - Add description about the configuration file in README.md
59
+ - Add a feature to load the configuration from an external file.
60
+ - Add a description about the configuration file in README.md.
30
61
 
31
62
  ## [0.2.0] - 2020-10-23
32
63
  ### Added
@@ -36,15 +67,15 @@ Nothing to record here.
36
67
  - Add a new task into `Rakefile` to generate RI docs.
37
68
  - The intention of the task is to verify RI docs.
38
69
 
39
- ### Fixed
70
+ ### Changed
40
71
  - Refactor some tests.
41
72
 
42
73
  ## [0.1.3] - 2020-10-15
43
- ### Fixed
74
+ ### Changed
44
75
  - Add help text for the `conf` command.
45
76
 
46
77
  ## [0.1.2] - 2020-10-15
47
- ### Fixed
78
+ ### Changed
48
79
  - Adapt the API change in `textrepo` (0.4.0).
49
80
 
50
81
  ## [0.1.0] - 2020-10-12
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ gemspec
6
6
  gem "rake", "~> 13.0"
7
7
  gem "minitest", "~> 5.0"
8
8
 
9
- gem 'textrepo', "~> 0.5"
9
+ gem 'textrepo', "~> 0.5.4"
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.0)
5
- textrepo (~> 0.5)
4
+ rbnotes (0.4.5)
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.3)
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
@@ -4,6 +4,9 @@
4
4
 
5
5
  Rbnotes is a simple utility to write a note in the single repository.
6
6
 
7
+ This document provides the basic information to use rbnotes.
8
+ You may find more useful information in [Wiki pages](https://github.com/mnbi/rbnotes/wiki).
9
+
7
10
  ## Installation
8
11
 
9
12
  Add this line to your application's Gemfile:
@@ -39,6 +42,8 @@ rbnotes [global_opts] [command] [command_opts] [args]
39
42
  - imports existing files
40
43
  - list
41
44
  - lists notes in the repository with their timestamps and subject
45
+ - search
46
+ - search a word (or words) in the repository
42
47
  - show
43
48
  - shows the content of a note
44
49
  - add
@@ -145,6 +150,38 @@ The short-hand notation of the home directory ("~") is usable.
145
150
 
146
151
  - :pager : specify a pager program
147
152
  - :editor : specify a editor program
153
+ - :searcher: specify a program to perform search
154
+ - :searcher_options: specify options to pass to the searcher program
155
+
156
+ Be careful to set `:searcher` and `:searcher_options`. The searcher
157
+ program must be expected to behave equivalent to `grep` with `-inRE`.
158
+ At least, its output must be the same format and it must runs
159
+ recursively to a directory.
160
+
161
+ If your favorite searcher is one of the followings, see the default
162
+ options which `textrepo` sets for those searchers. In most cases, you
163
+ don't have to set `:searcher_options` for them.
164
+
165
+ | searcher | default options in `textrepo` |
166
+ |:---------|:---------------------------------------------------|
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
+ | `rg` | `["-S", "-n", "--no-heading", "--color", "never"]` |
172
+
173
+ Those searcher names are used in macOS (with Homebrew). Any other OS
174
+ might use different names.
175
+
176
+ - `grep` and `egrep` -> BSD grep (macOS default)
177
+ - `ggrep` and `gegrep` -> GNU grep
178
+ - `rg` -> ripgrep
179
+
180
+ If the name is different, `:searcher_options` should be set with the
181
+ same value. For example, if you system use the name `gnugrep` as GNU
182
+ grep, and you want to use it as the searcher (that is, set `gnugrep`
183
+ to `:searcher`), you should set `:searcher_options` value with `["-i",
184
+ "-n", "-R", "-E"]`.
148
185
 
149
186
  ##### Default values for mandatory variables
150
187
 
@@ -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 => e
54
+ ArgumentError,
55
+ Errno::EACCES => e
47
56
  puts e.message
48
57
  exit 1
49
58
  end
@@ -1,6 +1,8 @@
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"
@@ -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::DEFAULT_CMD.new.execute(args, conf)
27
+ Builtins.default_cmd.new.execute(args, conf)
28
+ end
29
+
30
+ ##
31
+ # Shows the help message for the command.
32
+ #
33
+
34
+ def help
35
+ Builtins::Usage.new.execute(nil, nil)
21
36
  end
37
+
22
38
  end
23
39
 
24
40
  # :stopdoc:
@@ -29,54 +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 Help < Command
33
- def execute(_, _)
34
- puts <<USAGE
35
- usage: rbnotes [-c|--conf CONF_FILE] [command] [args]
48
+ class Usage < Command
36
49
 
37
- command:
38
- add : create a new note
39
- import FILE : import a FILE into the repository
50
+ def description
51
+ "Print usage"
52
+ end
40
53
 
41
- list PATTERN : list notes those timestamp matches PATTERN
54
+ def execute(_, _)
55
+ puts <<USAGE
56
+ Syntax:
57
+ #{Rbnotes::NAME} [-c| --conf CONF_FILE] [command] [args]
42
58
 
43
- PATTERN must be:
44
- (a) full qualified timestamp (with suffix): "20201030160200"
45
- (b) year and date part: "20201030"
46
- (c) year part only: "2020"
47
- (d) date part only: "1030"
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]
48
68
 
49
- show STAMP : show the note specified with STAMP
50
- update STAMP : edit the note with external editor
51
- delete STAMP : delete the note specified with STAMP
69
+ Further help for each command:
70
+ #{Rbnotes::NAME} help commands
71
+ #{Rbnotes::NAME} help [COMMAND]
52
72
 
53
- STAMP must be a sequence of digits to represent year, date and
54
- time (and suffix), such "20201030160200" or "20201030160200_012".
73
+ Further information:
74
+ https://github.com/mnbi/rbnotes/wiki
55
75
 
56
- show/update/delete reads its argument from the standard input when
57
- no argument was passed in the command line.
76
+ USAGE
77
+ end
58
78
 
59
- version : print version
60
- help : show help
79
+ def help
80
+ puts <<HELP_USAGE
81
+ usage:
82
+ #{Rbnotes::NAME} usage
61
83
 
62
- commands for development purpose:
63
- conf : print the current configuraitons
64
- repo : print the repository path
65
- stamp TIME_STR : convert TIME_STR into a timestamp
66
- time STAMP : convert STAMP into a time string
67
- USAGE
84
+ Print a short example of usage.
85
+ HELP_USAGE
68
86
  end
69
87
  end
70
88
 
71
89
  class Version < Command
90
+ def description
91
+ "Print version"
92
+ end
93
+
72
94
  def execute(_, _)
73
- rbnotes_version = "rbnotes #{Rbnotes::VERSION} (#{Rbnotes::RELEASE})"
95
+ rbnotes_version = "#{Rbnotes::NAME} #{Rbnotes::VERSION} (#{Rbnotes::RELEASE})"
74
96
  textrepo_version = "textrepo #{Textrepo::VERSION}"
75
97
  puts "#{rbnotes_version} [#{textrepo_version}]"
76
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
77
108
  end
78
109
 
79
110
  class Repo < Command
111
+ def description
112
+ "Print repository path"
113
+ end
114
+
80
115
  def execute(_, conf)
81
116
  name = conf[:repository_name]
82
117
  base = conf[:repository_base]
@@ -89,19 +124,49 @@ USAGE
89
124
  File.join(base, name)
90
125
  end
91
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
92
140
  end
93
141
 
94
142
  class Conf < Command
143
+ def description
144
+ "Print the current configuration"
145
+ end
146
+
95
147
  def execute(_, conf)
96
148
  conf.keys.sort.each { |k|
97
149
  puts "#{k}=#{conf[k]}"
98
150
  }
99
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
100
161
  end
101
162
 
102
163
  require "time"
103
164
 
104
165
  class Stamp < Command
166
+ def description
167
+ "Convert a time string into a timestamp string"
168
+ end
169
+
105
170
  def execute(args, _)
106
171
  time_str = args.shift
107
172
  unless time_str.nil?
@@ -111,9 +176,30 @@ USAGE
111
176
  super
112
177
  end
113
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
114
196
  end
115
197
 
116
198
  class Time < Command
199
+ def description
200
+ "Convert a timestamp into a time string"
201
+ end
202
+
117
203
  def execute(args, _)
118
204
  stamp = args.shift
119
205
  unless stamp.nil?
@@ -123,12 +209,41 @@ USAGE
123
209
  super
124
210
  end
125
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
126
227
  end
127
228
 
128
- DEFAULT_CMD = Help
129
- end
229
+ class << self
230
+ def default_cmd_name
231
+ "usage"
232
+ end
130
233
 
131
- DEFAULT_CMD_NAME = "help"
234
+ def default_cmd
235
+ Usage
236
+ end
237
+
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
132
247
 
133
248
  # :startdoc:
134
249
 
@@ -139,24 +254,28 @@ USAGE
139
254
  # of the class.
140
255
  #
141
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
142
261
  # load("import") -> Rbnotes::Commnads::Import
143
262
  # load("list") -> Rbnotes::Commands::List
263
+ # load("search") -> Rbnotes::Commands::Search
144
264
  # load("show") -> Rbnotes::Commands::Show
265
+ # load("update") -> Rbnotes::Commands::Update
145
266
 
146
267
  def load(cmd_name)
147
- cmd_name ||= DEFAULT_CMD_NAME
268
+ cmd_name ||= Builtins.default_cmd_name
148
269
  klass_name = cmd_name.capitalize
149
270
 
150
- klass = nil
151
- if Builtins.const_defined?(klass_name, false)
152
- klass = Builtins::const_get(klass_name, false)
153
- else
271
+ klass = Builtins.command(klass_name)
272
+ if klass.nil?
154
273
  begin
155
274
  require_relative "commands/#{cmd_name}"
156
275
  klass = const_get(klass_name, false)
157
276
  rescue LoadError => _
158
277
  STDERR.puts "unknown command: #{cmd_name}"
159
- klass = Builtins::DEFAULT_CMD
278
+ klass = Builtins.default_cmd
160
279
  end
161
280
  end
162
281
  klass.new