rbnotes 0.4.2 → 0.4.3

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: f48ac5666d917964e9c103c11be86b12736b81ced6e072be4707e1e943b6ff76
4
+ data.tar.gz: d29b9b68d6ebfcfdc7289962405a0390daed2705cd80b3beb50e036d2f8d9e85
5
5
  SHA512:
6
- metadata.gz: e28ed07cde6f385945a9ed3b92ff6402b8ec2dcdd2a75f6d1d0a8e391a2bf5e000245d708903fa815ec5faecfb2cfc39034240ef83a44818bd9a9ccb39c326ed
7
- data.tar.gz: 0e2a87a92c5b5a674d143c3d4461577976e5f62508d67ebbdb5202bfbc771c04aacaab520f8860e29429411f50677351f059e01a919e0836fc889b6285507fbd
6
+ metadata.gz: f5be0687fc189a5dad6178104a05af0f64e35fc44dd1a73bf677a232038b81b4f88e5562ca9f9e8f098152136c005ebdc334158d34652c0fe7a2bea8e13c4056
7
+ data.tar.gz: a1e5d671d93ff9efdbe33e7c6751984f851c39756304df7c874fe82df558b18b7f4f716d82253e99b2d8e21cc1d795d6b81c0f1ba665f8f3e99e38c30e4d19d8
@@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
+ ## [0.4.3] - 2020-11-08
11
+ ### Added
12
+ - Add a new command `export` to write out a note into a file (#51)
13
+ - Add individual help for each command. (#42)
14
+
15
+ ### Fixed
16
+ - Fix `add` fails without modification (#48)
17
+
10
18
  ## [0.4.2] - 2020-11-05
11
19
  ### Added
12
20
  - Add a feature to keep the timestamp in `update` command. (#44)
13
21
 
14
- ### Changed
22
+ ### Fixed
15
23
  - Fix issue #45: hanging up of `add` command.
16
24
 
17
25
  ## [0.4.1] - 2020-11-04
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.2)
4
+ rbnotes (0.4.3)
5
5
  textrepo (~> 0.5.4)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -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)
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]
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
@@ -29,6 +29,10 @@ module Rbnotes::Commands
29
29
  class Add < Command
30
30
  include ::Rbnotes::Utils
31
31
 
32
+ def description # :nodoc:
33
+ "Add a new note"
34
+ end
35
+
32
36
  def execute(args, conf)
33
37
  @opts = {}
34
38
  while args.size > 0
@@ -52,6 +56,12 @@ module Rbnotes::Commands
52
56
  raise Rbnotes::NoEditorError, candidates if editor.nil?
53
57
 
54
58
  tmpfile = run_with_tmpfile(editor, stamp.to_s)
59
+
60
+ unless FileTest.exist?(tmpfile)
61
+ puts "Cancel adding, since nothing to store"
62
+ return
63
+ end
64
+
55
65
  text = File.readlines(tmpfile)
56
66
 
57
67
  repo = Textrepo.init(conf)
@@ -72,6 +82,36 @@ module Rbnotes::Commands
72
82
  end
73
83
  end
74
84
 
85
+ def help # :nodoc:
86
+ puts <<HELP
87
+ usage:
88
+ #{Rbnotes::NAME} add [(-t|--timestamp) STAMP_PATTERN]
89
+
90
+ Add a new note to the repository. If no options, a new timestamp is
91
+ generated at the execution time, then it is attached to the note.
92
+
93
+ Accept an option with `-t STAMP_PATTERN` (or `--timestamp`), a
94
+ timestamp is generated according to `STAMP_PATTERN`.
95
+
96
+ STAMP_PATTERN could be one of followings:
97
+
98
+ "20201104172230_078" : full qualified timestamp string
99
+ "20201104172230" : full qualified timestamp string (no suffix)
100
+ "202011041722" : year, date and time (omit second part)
101
+ "11041722" : date and time (omit year and second part)
102
+
103
+ This command starts the external editor program to prepare text to
104
+ store. The editor program will be searched in the following order:
105
+
106
+ 1. configuration setting of ":editor"
107
+ 2. ENV["EDITOR"]
108
+ 3. "nano"
109
+ 4. "vi"
110
+
111
+ If none of the above editor is available, the execution fails.
112
+ HELP
113
+ end
114
+
75
115
  # :stopdoc:
76
116
  private
77
117
  def complement_timestamp_pattern(pattern)
@@ -1,18 +1,17 @@
1
- # :markup: markdown
1
+ module Rbnotes::Commands
2
2
 
3
- # Delete command deletes one note in the repository, which specified
4
- # with a given timestamp string. The timestamp string must be a fully
5
- # qualified one, like "20201016165130". The argument to specify a
6
- # note is mandatory. If no argument was passed, it would print help
7
- # message and exit.
8
- #
9
- # It does nothing when the specified note does not exist except to
10
- # print error message.
3
+ # Deletes a given note in the repository. The timestamp string must
4
+ # be a fully qualified one, like "20201016165130". If no argument
5
+ # was passed, it would try to read from the standard input.
6
+ #
7
+ # It does nothing to change the repository when the specified note
8
+ # does not exist.
11
9
 
12
- # :stopdoc:
10
+ class Delete < Command
11
+ def description # :nodoc:
12
+ "Delete a note"
13
+ end
13
14
 
14
- module Rbnotes
15
- class Commands::Delete < Commands::Command
16
15
  def execute(args, conf)
17
16
  stamp = Rbnotes::Utils.read_timestamp(args)
18
17
 
@@ -27,5 +26,18 @@ module Rbnotes
27
26
  puts "Delete [%s]" % stamp.to_s
28
27
  end
29
28
  end
29
+
30
+ def help # :nodoc:
31
+ puts <<HELP
32
+ usage:
33
+ #{Rbnotes::NAME} delete [TIMESTAMP]
34
+
35
+ Delete a given note. TIMESTAMP must be a fully qualified one, such
36
+ "20201016165130" or "20201016165130_012" if it has a suffix.
37
+
38
+ Delete reads its argument from the standard input when no argument was
39
+ passed in the command line.
40
+ HELP
41
+ end
30
42
  end
31
43
  end
@@ -0,0 +1,58 @@
1
+ require "pathname"
2
+
3
+ module Rbnotes::Commands
4
+
5
+ ##
6
+ # Writes out a given note into a specified file. The file will be
7
+ # created in the current working directory unless an absolute path
8
+ # is specified as a filename.
9
+ #
10
+ # When no argument was passed, would try to read a timestamp string
11
+ # from the standard input.
12
+
13
+ class Export < Command
14
+
15
+ def description # :nodoc:
16
+ "Write out a note into a file"
17
+ end
18
+
19
+ #
20
+ # :call-seq:
21
+ # execute([a String as timestring], Rbnotes::Conf or Hash) -> nil
22
+
23
+ def execute(args, conf)
24
+ stamp = Rbnotes::Utils.read_timestamp(args)
25
+
26
+ repo = Textrepo.init(conf)
27
+ begin
28
+ content = repo.read(stamp)
29
+ rescue Textrepo::MissingTimestampError => _
30
+ raise MissingTimestampError, stamp
31
+ end
32
+
33
+ pathname = Pathname.new(args.shift || "#{stamp}.md")
34
+ pathname.parent.mkpath
35
+ pathname.open("w"){ |f| f.puts content }
36
+ puts "Export a note [%s] into a file [%s]" % [stamp, pathname]
37
+ end
38
+
39
+ def help # :nodoc:
40
+ puts <<HELP
41
+ usage:
42
+ #{Rbnotes::NAME} export [TIMESTAMP [FILENAME]]
43
+
44
+ Write out a given note into a specified file. TIMESTAMP must be a
45
+ fully qualified one, such "20201108141600", or "20201108141600_012" if
46
+ it has a suffix. FILENAME is optional. When it omitted, the filename
47
+ would be a timestamp string with ".md" as its extension, such
48
+ "20201108141600.md"
49
+
50
+ The file will be created into the current working directory unless an
51
+ absolute path is specified as FILENAME.
52
+
53
+ When no argument was passed, it would try to read a timestamp string
54
+ from the standard input. Then, FILENAME would be regarded as omitted.
55
+ HELP
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,98 @@
1
+ module Rbnotes::Commands
2
+
3
+ ##
4
+ # Shows help message for the command which specifies with the
5
+ # argument.
6
+
7
+ class Help < Command
8
+
9
+ def description # :nodoc:
10
+ "Provide help on each command"
11
+ end
12
+
13
+ ##
14
+ # :call-seq:
15
+ # execute(["add"], Rbnotes::Conf or Hash) -> nil
16
+ # execute(["delete"], Rbnotes::Conf or Hash) -> nil
17
+
18
+ def execute(args, conf)
19
+ cmd_name = args.shift
20
+ case cmd_name
21
+ when nil
22
+ self.help
23
+ when "commands"
24
+ print_commands
25
+ else
26
+ Commands.load(cmd_name).help
27
+ end
28
+ end
29
+
30
+ def help # :nodoc:
31
+ puts <<HELP
32
+ #{Rbnotes::NAME.capitalize} is a simple tool to write a note into a single repository.
33
+
34
+ When creates a new note, a timestamp is attached to the note. #{Rbnotes::NAME.capitalize}
35
+ manages notes with those timestamps, such update, delete, ...etc.
36
+
37
+ Timestamp is a series of digits which represents year, date, and time.
38
+ It looks like "20201106121100", means "2020-11-06 12:11:00". It is
39
+ generated in the local time.
40
+
41
+ usage:
42
+ #{Rbnotes::NAME} [option] [command] [args]
43
+
44
+ option:
45
+ -c, --conf [CONF_FILE] : specifiy the configuration file
46
+ -v, --version : print version
47
+ -h, --help : show this message
48
+
49
+ CONF_FILE must be written in YAML. To know about details of the
50
+ configuration file, see README.md or Wiki page.
51
+
52
+ Further help:
53
+ #{Rbnotes::NAME} help commands
54
+ #{Rbnotes::NAME} help COMMAND
55
+ #{Rbnotes::NAME} usage
56
+
57
+ Further information:
58
+ https://github.com/mnbi/rbnotes/wiki
59
+ HELP
60
+ end
61
+
62
+ # :stopdoc:
63
+ private
64
+
65
+ def print_commands
66
+ Dir.glob("*.rb", :base => __dir__) { |rb|
67
+ next if rb == "help.rb"
68
+ require_relative rb
69
+ }
70
+ commands = Commands.constants.difference([:Builtins, :Command])
71
+ builtins = Commands::Builtins.constants
72
+
73
+ puts "#{Rbnotes::NAME.capitalize} Commands:"
74
+ print_commands_desc(commands.sort)
75
+ puts
76
+ puts "for development purpose"
77
+ print_builtins_desc(builtins.sort)
78
+ end
79
+
80
+ def print_commands_desc(commands)
81
+ print_desc(Commands, commands)
82
+ end
83
+
84
+ def print_builtins_desc(builtins)
85
+ print_desc(Commands::Builtins, builtins)
86
+ end
87
+
88
+ def print_desc(mod, commands)
89
+ commands.map { |cmd|
90
+ name = "#{cmd.to_s.downcase} "[0, 8]
91
+ desc = mod.const_get(cmd, false).new.description
92
+ puts " #{name} #{desc}"
93
+ }
94
+ end
95
+
96
+ # :startdoc:
97
+ end
98
+ end
@@ -1,5 +1,29 @@
1
- module Rbnotes
2
- class Commands::Import < Commands::Command
1
+ module Rbnotes::Commands
2
+
3
+ ##
4
+ # Imports a existing file which specified by the argument as a note.
5
+ #
6
+ # A timestamp is generated referring to the birthtime of the given
7
+ # file. If birthtime is not available on the system, use mtime
8
+ # (modification time).
9
+ #
10
+ # Occasionally, there is another note which has the same timestmap
11
+ # in the repository. Then, tries to create a new timestamp with a
12
+ # suffix. Unluckily, when such timestamp with a suffix already
13
+ # exists, tries to create a new one with increasing suffix. Suffix
14
+ # will be "001", "002", ..., or "999". In worst case, all suffix
15
+ # might have been already used. Then, abandons to import.
16
+
17
+ class Import < Command
18
+
19
+ def description # :nodoc:
20
+ "Import a file as a note"
21
+ end
22
+
23
+ ##
24
+ # :call-seq:
25
+ # execute([PATHNAME], Rbnotes::Conf or Hash) -> nil
26
+
3
27
  def execute(args, conf)
4
28
  file = args.shift
5
29
  unless file.nil?
@@ -58,5 +82,18 @@ module Rbnotes
58
82
  super
59
83
  end
60
84
  end
85
+
86
+ def help # :nodoc:
87
+ puts <<HELP
88
+ usage:
89
+ #{Rbnotes::NAME} import FILE
90
+
91
+ Imports a existing file which specified by the argument as a note.
92
+
93
+ A timestamp is generated referring to the birthtime of the given file.
94
+ If birthtime is not available on the system, use mtime (modification
95
+ time).
96
+ HELP
97
+ end
61
98
  end
62
99
  end
@@ -1,15 +1,20 @@
1
1
  require "unicode/display_width"
2
2
  require "io/console/size"
3
3
 
4
- module Rbnotes
4
+ module Rbnotes::Commands
5
+
5
6
  ##
6
7
  # Defines `list` command for `rbnotes`. See the document of execute
7
8
  # method to know about the behavior of this command.
8
9
 
9
- class Commands::List < Commands::Command
10
+ class List < Command
11
+
12
+ def description # :nodoc:
13
+ "List notes"
14
+ end
10
15
 
11
16
  ##
12
- # Shows the list of notes in the repository. The only argument is
17
+ # Shows a list of notes in the repository. The only argument is
13
18
  # optional. If it passed, it must be an timestamp pattern. A
14
19
  # timestamp is an instance of Textrepo::Timestamp class. A
15
20
  # timestamp pattern is a string which would match several
@@ -48,6 +53,25 @@ module Rbnotes
48
53
  }
49
54
  end
50
55
 
56
+ def help # :nodoc:
57
+ puts <<HELP
58
+ usage:
59
+ #{Rbnotes::NAME} list [STAMP_PATTERN]
60
+
61
+ Show a list of notes. When no arguments, make a list with all notes
62
+ in the repository. When specified STAMP_PATTERN, only those match the
63
+ pattern are listed.
64
+
65
+ STAMP_PATTERN must be:
66
+
67
+ (a) full qualified timestamp (with suffix): "20201030160200"
68
+ (b) year and date part: "20201030"
69
+ (c) year and month part: "202010"
70
+ (d) year part only: "2020"
71
+ (e) date part only: "1030"
72
+ HELP
73
+ end
74
+
51
75
  # :stopdoc:
52
76
 
53
77
  private
@@ -1,4 +1,4 @@
1
- module Rbnotes
1
+ module Rbnotes::Commands
2
2
 
3
3
  ##
4
4
  # Searches a given pattern in notes those have timestamps match a
@@ -22,7 +22,12 @@ module Rbnotes
22
22
  # See the document of `Rbnotes::Commands::List#execute` to know about
23
23
  # a timestamp pattern.
24
24
 
25
- class Commands::Search < Commands::Command
25
+ class Search < Command
26
+
27
+ def description # :nodoc:
28
+ "Search a given pattern in notes"
29
+ end
30
+
26
31
  def execute(args, conf)
27
32
  pattern = args.shift
28
33
  raise MissingArgumentError, args if pattern.nil?
@@ -40,5 +45,23 @@ module Rbnotes
40
45
  }
41
46
  end
42
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
43
66
  end
44
67
  end
@@ -1,5 +1,23 @@
1
- module Rbnotes
2
- class Commands::Show < Commands::Command
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,35 +1,32 @@
1
1
  module Rbnotes::Commands
2
+
2
3
  ##
3
4
  # Updates the content of the note associated with given timestamp.
4
- # Actual modification is done interactively by the external editor.
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
12
  # When "-k" (or "--keep") option is specified, the timestamp will
9
13
  # remain unchanged.
10
14
  #
11
- # A timestamp string must be specified as the only argument. It
12
- # must exactly match to the one of the target note in the
13
- # repository. When the given timestamp was not found, the command
14
- # fails.
15
- #
16
- # Timestamp which is associated to the target note will be newly
17
- # generated with the command execution time. That is, the timestamp
18
- # before the command exection will be obsolete.
19
- #
20
- # This command starts the external editor program to edit the
21
- # content of the note. The editor program will be searched as same
22
- # as add command.
15
+ # Actual modification is done interactively by the external editor.
23
16
  #
24
- # If none of editors is available, the command fails.
17
+ # The editor program will be searched as same as add command. If
18
+ # none of editors is available, the execution fails.
25
19
 
26
20
  class Update < Command
27
21
  include ::Rbnotes::Utils
28
22
 
23
+ def description # :nodoc:
24
+ "Update the content of a note"
25
+ end
26
+
29
27
  ##
30
28
  # The 1st and only one argument is the timestamp to speficy the
31
- # note to update. Returns the new timestamp which is associated
32
- # to the note updated.
29
+ # note to update.
33
30
  #
34
31
  # :call-seq:
35
32
  # "20201020112233" -> "20201021123400"
@@ -82,5 +79,27 @@ module Rbnotes::Commands
82
79
  puts "Nothing is updated, since the specified content is empty."
83
80
  end
84
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
85
104
  end
86
105
  end
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.2"
3
- RELEASE = "2020-11-05"
2
+ VERSION = "0.4.3"
3
+ RELEASE = "2020-11-08"
4
4
  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.2
4
+ version: 0.4.3
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-05 00:00:00.000000000 Z
11
+ date: 2020-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo
@@ -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