rbnotes 0.4.2 → 0.4.7

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: 7a43f87f2f4b03c9f8e27d06eb4fc426abb6dafbd420d5bbbcdb4ec2ea38d497
4
- data.tar.gz: 0f9c060bfefde2e6c3f611d7d7e683fdd5ced20327b3ae6a3cbfcac39cdaf5a3
3
+ metadata.gz: a6625e8e9365a5c69cb9fd1f9d227e04247edda6ddbb9f5d3d442e0e7f87ac96
4
+ data.tar.gz: 5b00c1ecef74b47957112de785c57e249aa35b07c8809401872f75dec392f4c1
5
5
  SHA512:
6
- metadata.gz: e28ed07cde6f385945a9ed3b92ff6402b8ec2dcdd2a75f6d1d0a8e391a2bf5e000245d708903fa815ec5faecfb2cfc39034240ef83a44818bd9a9ccb39c326ed
7
- data.tar.gz: 0e2a87a92c5b5a674d143c3d4461577976e5f62508d67ebbdb5202bfbc771c04aacaab520f8860e29429411f50677351f059e01a919e0836fc889b6285507fbd
6
+ metadata.gz: 3d6e047ed738940dcbadd14bc8c176c486404951e4349eebe82c8bfbd92c1ad09fe996adb7c5db8bfdbf20ca364b6cebabd5dad3a2edbd9a597a2ad373a658ec
7
+ data.tar.gz: 504add631c2960e0b12eabce1075ba6d90745db531ebb95b1721a46bee236d7906d489169e0161d9e6213627cd28ceea59a8db1bb0e9c3f5ab0ba8878befb3c7
@@ -7,15 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
- ## [0.4.2] - 2020-11-05
10
+ ## [0.4.7] - 2020-11-15
11
+ ### Changed
12
+ - Beautify output of the `search` command. (#63)
13
+
14
+ ### Fixed
15
+ - Fix issue #61: `list` command fails in pipeline.
16
+
17
+ ## [0.4.6] - 2020-11-13
11
18
  ### Added
12
- - Add a feature to keep the timestamp in `update` command. (#44)
19
+ - Add a new command `pick` to select a note with picker program. (#59)
20
+
21
+ ## [0.4.5] - 2020-11-12
22
+ ### Changed
23
+ - Add a feature to accept multiple args for `list`. (#57)
24
+
25
+ ### Fixed
26
+ - Fix issue #54: Notes list does not sort correctly.
27
+
28
+ ## [0.4.4] - 2020-11-09
29
+ ### Changed
30
+ - Add a feature to use a keyword as an argument for `list`. (#47)
31
+
32
+ ## [0.4.3] - 2020-11-08
33
+ ### Added
34
+ - Add a new command `export` to write out a note into a file. (#51)
35
+ - Add individual help for each command. (#42)
36
+
37
+ ### Fixed
38
+ - Fix `add` fails without modification (#48)
13
39
 
40
+ ## [0.4.2] - 2020-11-05
14
41
  ### Changed
42
+ - Add a feature to keep the timestamp in `update` command. (#44)
43
+
44
+ ### Fixed
15
45
  - Fix issue #45: hanging up of `add` command.
16
46
 
17
47
  ## [0.4.1] - 2020-11-04
18
- ### Added
48
+ ### Changed
19
49
  - Add a feature to accept a timestamp in `add` command. (#34)
20
50
 
21
51
  ## [0.4.0] - 2020-11-03
@@ -24,20 +54,21 @@ Nothing to record here.
24
54
 
25
55
  ## [0.3.1] - 2020-10-30
26
56
  ### Added
27
- - Add feature to specify configuration file in the command line. (#21)
57
+ - Add a feature to specify configuration file in the command
58
+ line. (#21)
28
59
 
29
60
  ## [0.3.0] - 2020-10-29
30
- ### Added
61
+ ### Changed
31
62
  - Add feature to read argument from the standard input. (#27)
32
63
 
33
64
  ## [0.2.2] - 2020-10-27
34
- ### Added
35
- - Add feature to accept a timestamp pattern in `list` command. (#22)
65
+ ### Changed
66
+ - Add a feature to accept a timestamp pattern in `list` command. (#22)
36
67
 
37
68
  ## [0.2.1] - 2020-10-25
38
69
  ### Added
39
- - Add feature to load the configuration from an external file.
40
- - Add description about the configuration file in README.md
70
+ - Add a feature to load the configuration from an external file.
71
+ - Add a description about the configuration file in README.md.
41
72
 
42
73
  ## [0.2.0] - 2020-10-23
43
74
  ### Added
@@ -47,15 +78,15 @@ Nothing to record here.
47
78
  - Add a new task into `Rakefile` to generate RI docs.
48
79
  - The intention of the task is to verify RI docs.
49
80
 
50
- ### Fixed
81
+ ### Changed
51
82
  - Refactor some tests.
52
83
 
53
84
  ## [0.1.3] - 2020-10-15
54
- ### Fixed
85
+ ### Changed
55
86
  - Add help text for the `conf` command.
56
87
 
57
88
  ## [0.1.2] - 2020-10-15
58
- ### Fixed
89
+ ### Changed
59
90
  - Adapt the API change in `textrepo` (0.4.0).
60
91
 
61
92
  ## [0.1.0] - 2020-10-12
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.2)
4
+ rbnotes (0.4.7)
5
5
  textrepo (~> 0.5.4)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -10,7 +10,7 @@ GEM
10
10
  specs:
11
11
  minitest (5.14.2)
12
12
  rake (13.0.1)
13
- textrepo (0.5.4)
13
+ textrepo (0.5.6)
14
14
  unicode-display_width (1.7.0)
15
15
 
16
16
  PLATFORMS
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
@@ -4,4 +4,5 @@
4
4
  :repository_name: "notes"
5
5
  :repository_base: "~"
6
6
  :pager: "bat -l md"
7
+ :picker: "fzf"
7
8
  :editor: "/usr/local/bin/emacsclient"
@@ -4,4 +4,5 @@
4
4
  :repository_name: "notes"
5
5
  :repository_base: "tmp"
6
6
  :pager: "bat -l md"
7
+ :picker: "fzf"
7
8
  :editor: "/usr/local/bin/emacsclient"
@@ -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
@@ -40,10 +48,16 @@ app = App.new
40
48
  begin
41
49
  app.parse_global_options(ARGV)
42
50
  app.run(ARGV)
51
+ rescue Errno::EPIPE => e
52
+ # Fix issue #61: When the pipeline which rbnotes connects is
53
+ # discarded by the other program, the execption was raised. It does
54
+ # not end abnormally for rbnotes. So, just ignores the exception.
55
+ exit 0
43
56
  rescue MissingArgumentError, MissingTimestampError,
44
57
  NoEditorError, ProgramAbortError,
45
58
  Textrepo::InvalidTimestampStringError,
46
- ArgumentError => e
59
+ ArgumentError,
60
+ Errno::EACCES => e
47
61
  puts e.message
48
62
  exit 1
49
63
  end
@@ -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
@@ -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)
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 Help < Command
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
- list [STAMP_PATTERN] : list notes those timestamp matches PATTERN
49
- search PATTERN [STAMP_PATTERN] : search PATTERN
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
- version : print version
73
- help : show help
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
- command for development:
76
- conf : print the current configuraitons
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
- For more information, see Wiki page.
82
- - https://github.com/mnbi/rbnotes/wiki
79
+ def help
80
+ puts <<HELP_USAGE
81
+ usage:
82
+ #{Rbnotes::NAME} usage
83
83
 
84
- USAGE
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 = "rbnotes #{Rbnotes::VERSION} (#{Rbnotes::RELEASE})"
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
- DEFAULT_CMD = Help
146
- end
229
+ class << self
230
+ def default_cmd_name
231
+ "usage"
232
+ end
233
+
234
+ def default_cmd
235
+ Usage
236
+ end
147
237
 
148
- DEFAULT_CMD_NAME = "help"
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 ||= DEFAULT_CMD_NAME
268
+ cmd_name ||= Builtins.default_cmd_name
165
269
  klass_name = cmd_name.capitalize
166
270
 
167
- klass = nil
168
- if Builtins.const_defined?(klass_name, false)
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::DEFAULT_CMD
278
+ klass = Builtins.default_cmd
177
279
  end
178
280
  end
179
281
  klass.new