rbnotes 0.4.9 → 0.4.10

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: 4e4e20e7274cc9e4f9d013340447f7fb06a7dcf45d8536d71e6c6f456a29d310
4
- data.tar.gz: e41d785998768d9b4655575ae5303240de437243b6349ecd4ce147a5a051359b
3
+ metadata.gz: 7e6de4675ffb2b409f72f240e4509a6d254793d977a8dd68cc54cf6d0c839e3d
4
+ data.tar.gz: 364d4deb47d049af7145024cfb3151639ea9cf0504963c1b72e5a15e465a84a6
5
5
  SHA512:
6
- metadata.gz: 5b2f313ceab8c9a18205189235d72f13c48b7724ba8b15e2651bfb79e1af62e55e1fc1d855eaa0b6eadb3b715e3fd85bd70fe692bbf18d706191a81532a27b0d
7
- data.tar.gz: 430276b6461f3502e8f74463451c67a4ddfe40fe7abd5a676abbb6f0ac24980890de6f6ac22f5a7dd64827283c7b101323d4c21b6b210e8c99a577823244885f
6
+ metadata.gz: bf90b255e23257a921f7a9254d4df5233f97394e73368f27f6a4a8e96989fa3aa76ab55fca69b201ecd9a15264d5d07cf974ee9b745854ca80d3c962accbe37a
7
+ data.tar.gz: c9fca12a0a6a71562a968775b09e3ebf7bda202ce7251666ab7b727236c47f8b5981d7ee703b94bfc22fae038cc161f76b10ed413ca28bcac3a9d9e0417f7f83
@@ -7,6 +7,13 @@ 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] - 2020-11-20
11
+ ### Added
12
+ - Add a new command `commands` to show all command names. (#71)
13
+
14
+ ### Fixed
15
+ - Fix issue #69: crashes with invalid timestamp pattern.
16
+
10
17
  ## [0.4.9] - 2020-11-17
11
18
  ### Added
12
19
  - Add a new option `--week` to the `list` command. (#67)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.9)
4
+ rbnotes (0.4.10)
5
5
  textrepo (~> 0.5.4)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -56,6 +56,7 @@ rescue Errno::EPIPE => e
56
56
  rescue MissingArgumentError, MissingTimestampError,
57
57
  NoEditorError, ProgramAbortError,
58
58
  Textrepo::InvalidTimestampStringError,
59
+ InvalidTimestampPatternError,
59
60
  ArgumentError,
60
61
  Errno::EACCES => e
61
62
  puts e.message
@@ -58,13 +58,14 @@ Syntax:
58
58
 
59
59
  Example usage:
60
60
  #{Rbnotes::NAME} add [-t STAMP_PATTERN]
61
+ #{Rbnotes::NAME} commands [-d]
61
62
  #{Rbnotes::NAME} delete [TIMESTAMP]
62
63
  #{Rbnotes::NAME} export [TIMESTAMP [FILENAME]]
63
64
  #{Rbnotes::NAME} import FILE
64
65
  #{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
65
66
  #{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
66
67
  #{Rbnotes::NAME} show [TIMESTAMP]
67
- #{Rbnotes::NAME} update [TIMESTAMP]
68
+ #{Rbnotes::NAME} update [-k] [TIMESTAMP]
68
69
 
69
70
  Further help for each command:
70
71
  #{Rbnotes::NAME} help commands
@@ -0,0 +1,121 @@
1
+ module Rbnotes::Commands
2
+ ##
3
+ # Prints all command names into a single line. When `-d` (or
4
+ # `--deve-commands`) was specified, development commands (such
5
+ # `conf`) would be also printed in addition to general commands.
6
+
7
+ class Commands < Command
8
+
9
+ def description # :nodoc:
10
+ "Print all command names into a single line"
11
+ end
12
+
13
+ def execute(args, conf)
14
+ @opts = {}
15
+ while args.size > 0
16
+ arg = args.shift
17
+ case arg.to_s
18
+ when "" # no options
19
+ break
20
+ when "-d", "--deve-commands"
21
+ @opts[:print_deve_commands] = true
22
+ else # invalid options or args
23
+ args.unshift(arg)
24
+ raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
25
+ end
26
+ end
27
+
28
+ puts commands(@opts[:print_deve_commands]).join(" ")
29
+ end
30
+
31
+ def help
32
+ puts <<HELP
33
+ usage:
34
+ #{Rbnotes::NAME} [-d|--deve-commands]
35
+
36
+ Print all command names into a single line. If "-d" option (or
37
+ "--deve-commands") is specified, commands for development purpose are
38
+ also printed.
39
+
40
+ HELP
41
+ print_commands
42
+ end
43
+
44
+ # :stopdoc:
45
+ private
46
+
47
+ ##
48
+ # Enumerates all command names.
49
+ #
50
+ # :call-seq:
51
+ # commands(builtins = false) -> [Array of Strings]
52
+
53
+ def commands(include_builtins = false)
54
+ names = external_commands.map { |cmd| cmd.to_s.downcase }
55
+ names += builtin_commands.map { |cmd| cmd.to_s.downcase } if include_builtins
56
+ names
57
+ end
58
+
59
+ def external_commands
60
+ Dir.glob("*.rb", :base => __dir__) { |rb|
61
+ require_relative rb
62
+ }
63
+ Rbnotes::Commands.constants.difference([:Builtins, :Command]).sort
64
+ end
65
+
66
+ def builtin_commands
67
+ Rbnotes::Commands::Builtins.constants.sort
68
+ end
69
+
70
+ def print_commands
71
+ Dir.glob("*.rb", :base => __dir__) { |rb|
72
+ require_relative rb
73
+ }
74
+ puts "#{Rbnotes::NAME.capitalize} Commands:"
75
+ print_commands_desc(external_commands)
76
+ puts
77
+ puts "for development purpose"
78
+ print_builtins_desc(builtin_commands)
79
+ end
80
+
81
+ def print_commands_desc(commands)
82
+ print_desc(Rbnotes::Commands, commands)
83
+ end
84
+
85
+ def print_builtins_desc(builtins)
86
+ print_desc(Rbnotes::Commands::Builtins, builtins)
87
+ end
88
+
89
+ class CmdNames
90
+ attr_reader :symbol, :name, :size
91
+ def initialize(cmd)
92
+ @symbol = cmd
93
+ @name = cmd.to_s.downcase
94
+ @size = name.size
95
+ end
96
+ end
97
+
98
+ def print_desc(mod, commands)
99
+ cmds = commands.map { |cmd| CmdNames.new(cmd) }
100
+ name_part_size = cmds.map(&:size).max + 2
101
+ cmds.map { |cmd|
102
+ puts "#{spaces(4)}#{name_part(cmd.name, name_part_size)} #{desc_part(cmd.symbol, mod)}"
103
+ }
104
+ end
105
+
106
+ def name_part(name, size)
107
+ "#{name}#{spaces(size)}"[0, size]
108
+ end
109
+
110
+ def desc_part(symbol, mod)
111
+ mod.const_get(symbol, false).new.description
112
+ end
113
+
114
+ def spaces(size)
115
+ Array.new(size, " ").join
116
+ end
117
+
118
+ # :startdoc:
119
+
120
+ end
121
+ end
@@ -7,7 +7,7 @@ module Rbnotes::Commands
7
7
  class Help < Command
8
8
 
9
9
  def description # :nodoc:
10
- "Provide help on each command"
10
+ "Print help of each command"
11
11
  end
12
12
 
13
13
  ##
@@ -20,8 +20,6 @@ module Rbnotes::Commands
20
20
  case cmd_name
21
21
  when nil
22
22
  self.help
23
- when "commands"
24
- print_commands
25
23
  else
26
24
  Commands.load(cmd_name).help
27
25
  end
@@ -59,40 +57,5 @@ Further information:
59
57
  HELP
60
58
  end
61
59
 
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
60
  end
98
61
  end
@@ -82,7 +82,7 @@ module Rbnotes::Commands
82
82
  def help # :nodoc:
83
83
  puts <<HELP
84
84
  usage:
85
- #{Rbnotes::NAME} update [TIMESTAMP]
85
+ #{Rbnotes::NAME} update [-k|--keep] [TIMESTAMP]
86
86
 
87
87
  Updates the content of the note associated with given timestamp.
88
88
 
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.9"
3
- RELEASE = "2020-11-17"
2
+ VERSION = "0.4.10"
3
+ RELEASE = "2020-11-20"
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.9
4
+ version: 0.4.10
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-17 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo
@@ -63,6 +63,7 @@ files:
63
63
  - lib/rbnotes.rb
64
64
  - lib/rbnotes/commands.rb
65
65
  - lib/rbnotes/commands/add.rb
66
+ - lib/rbnotes/commands/commands.rb
66
67
  - lib/rbnotes/commands/delete.rb
67
68
  - lib/rbnotes/commands/export.rb
68
69
  - lib/rbnotes/commands/help.rb