rbnotes 0.3.0 → 0.3.1

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: 906c366a81295b7d9a1c2e86ad2bd6f1d35f410ac7360f1e2067c0a0f8e4f48b
4
- data.tar.gz: d2af84cbd9ddbb60fe6f21ddffb9c072ebe0b767e8c8ab6ae4cac0c1bca30acd
3
+ metadata.gz: 2cb54d2116edee3136979232f749434f0b4c068fa5162321bd02dfc96fcd8ece
4
+ data.tar.gz: 1d3d61b2cafa2d7a2825deb764ee232729e0a7bc8afa51868dbd98db2b7c016f
5
5
  SHA512:
6
- metadata.gz: 5fa3929995ebda0b4970c18516dadc37b5ddeb99d2a33c39ce90ac9f8bb90556c7a406b995b3373e4bc559c56b57750f0a0796f53b3d25624d1a891d2da456d1
7
- data.tar.gz: 99c4dd49875b4cf1f262cbd845bbccb6482449f0a1573ed188b50cd6814c1220cc7cea1032cc2b6bbaaeb2e05c4f21f8a241e8931ff8d44128e72f8457c1b113
6
+ metadata.gz: 07a40884e1f0a73bc4b3d70104d98d56814084ce643b86715cf739ece89124da45236cccc4ba881f78e176b8ee318eceaa5974811e4f990d81dce17a018b8a74
7
+ data.tar.gz: fd70d8ed8d461610cf0f60fe506588414abbd2f9a6fe9deabe8de49ca7a3146d49efcb799b25bb4f66158afc4298643993f1d2a3a7e21d095efe2e7462d8792f
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
+ ## [0.3.1] - 2020-10-30
11
+ ### Added
12
+ - Add feature to specify configuration file in the command line. (#21)
13
+
10
14
  ## [0.3.0] - 2020-10-29
11
15
  ### Added
12
16
  - Add feature to read argument from the standard input. (#27)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.3.0)
4
+ rbnotes (0.3.1)
5
5
  textrepo (~> 0.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.4.4)
13
+ textrepo (0.4.5)
14
14
  unicode-display_width (1.7.0)
15
15
 
16
16
  PLATFORMS
data/README.md CHANGED
@@ -28,6 +28,11 @@ General syntax is:
28
28
  rbnotes [global_opts] [command] [command_opts] [args]
29
29
  ```
30
30
 
31
+ ### Global options
32
+
33
+ - "-c CONF_FILE", "--conf"
34
+ - specifies a configuration file
35
+
31
36
  ### Commands
32
37
 
33
38
  - import
@@ -57,6 +62,8 @@ Searches the configuration file in the following order:
57
62
 
58
63
  None of them is found, then the default configuration is used.
59
64
 
65
+ The global option "-c CONF_FILE" will override the location.
66
+
60
67
  #### Content
61
68
 
62
69
  The format of the configuration file must be written in YAML.
@@ -75,14 +82,16 @@ A real example:
75
82
 
76
83
  ``` yaml
77
84
  ---
78
- :run_mode: :development
85
+ :run_mode: :production
79
86
  :repository_type: :file_system
80
87
  :repository_name: "notes"
81
88
  :repository_base: "~"
82
- :pager: "bat"
89
+ :pager: "bat -l md"
83
90
  :editor: "/usr/local/bin/emacsclient"
84
91
  ```
85
92
 
93
+ The content is identical to `conf/config.yml`.
94
+
86
95
  #### Variables
87
96
 
88
97
  ##### :run-mode (mandatory)
@@ -124,8 +133,13 @@ the `:repository_name` value. It would be:
124
133
 
125
134
  > :repository_base/:repository_name
126
135
 
127
- The value must be an absolute path. The short-hand notation of the
128
- home directory ("~") is usable.
136
+ The value is recommended to be an absolute path in the production
137
+ time, since relative path will be expanded with the current working
138
+ directory. However, in the development and testing time, the relative
139
+ path may be useful. See `conf/config_deve.yml` or
140
+ `conf/config_test.yml`.
141
+
142
+ The short-hand notation of the home directory ("~") is usable.
129
143
 
130
144
  ##### Miscellaneous variables (optional)
131
145
 
@@ -0,0 +1,7 @@
1
+ ---
2
+ :run_mode: :production
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "~"
6
+ :pager: "bat -l md"
7
+ :editor: "/usr/local/bin/emacsclient"
@@ -0,0 +1,7 @@
1
+ ---
2
+ :run_mode: :development
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "tmp"
6
+ :pager: "bat -l md"
7
+ :editor: "/usr/local/bin/emacsclient"
@@ -0,0 +1,5 @@
1
+ ---
2
+ :run_mode: :test
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "test/sandbox"
@@ -7,17 +7,45 @@ include Rbnotes
7
7
  DEBUG = true
8
8
 
9
9
  class App
10
+ def initialize
11
+ @gopts = {}
12
+ end
13
+
14
+ def options
15
+ @gopts
16
+ end
17
+
18
+ def parse_global_options(args)
19
+ while args.size > 0
20
+ arg = args.shift
21
+ case arg
22
+ when "-c", "--conf"
23
+ file = args.shift
24
+ raise ArgumentError, args.unshift(arg) if file.nil?
25
+ file = File.expand_path(file)
26
+ raise ArgumentError, "no such file: %s" % file unless FileTest.exist?(file)
27
+ @gopts[:conf_file] = file
28
+ else
29
+ args.unshift(arg)
30
+ break
31
+ end
32
+ end
33
+ end
34
+
10
35
  def run(args)
11
36
  cmd = args.shift
12
- Commands.load(cmd).execute(args, Rbnotes.conf)
37
+ Commands.load(cmd).execute(args, Rbnotes.conf(@gopts[:conf_file]))
13
38
  end
14
39
  end
15
40
 
16
41
  app = App.new
17
42
  begin
43
+ app.parse_global_options(ARGV)
18
44
  app.run(ARGV)
19
45
  rescue MissingArgumentError, MissingTimestampError,
20
- InvalidTimestampStringError, NoEditorError, ProgramAbortError => e
46
+ NoEditorError, ProgramAbortError,
47
+ Textrepo::InvalidTimestampStringError,
48
+ ArgumentError => e
21
49
  puts e.message
22
50
  exit 1
23
51
  end
@@ -2,16 +2,20 @@ module Rbnotes
2
2
  ##
3
3
  # This module defines all command classes of rbnotes. Each command
4
4
  # class must be derived from Rbnotes::Commands::Command class.
5
+
5
6
  module Commands
6
7
  ##
7
8
  # The base class for a command class.
9
+
8
10
  class Command
11
+
9
12
  ##
10
13
  # :call-seq:
11
- # Array, Hash -> nil
14
+ # execute(Array, Hash) -> nil
15
+ #
12
16
  # - Array: arguments for each command
13
17
  # - Hash : rbnotes configuration
14
- #
18
+
15
19
  def execute(args, conf)
16
20
  Builtins::DEFAULT_CMD.new.execute(args, conf)
17
21
  end
@@ -28,22 +32,38 @@ module Rbnotes
28
32
  class Help < Command
29
33
  def execute(_, _)
30
34
  puts <<USAGE
31
- usage: rbnotes [command] [args]
35
+ usage: rbnotes [-c|--conf CONF_FILE] [command] [args]
32
36
 
33
37
  command:
34
- add : create a new note
35
- update STAMP : edit the note with external editor
36
- import FILE : import a FILE into the repository
37
- list NUM : list NUM notes
38
- show STAMP : show the note specified with STAMP
39
- delete STAMP : delete the note specified with STAMP
40
-
41
- conf : print the current configuraitons
42
- repo : print the repository path
43
- stamp TIME_STR : convert TIME_STR into a timestamp
44
- time STAMP : convert STAMP into a time string
45
- version : print version
46
- help : show help
38
+ add : create a new note
39
+ import FILE : import a FILE into the repository
40
+
41
+ list PATTERN : list notes those timestamp matches PATTERN
42
+
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"
48
+
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
52
+
53
+ STAMP must be a sequence of digits to represent year, date and
54
+ time (and suffix), such "20201030160200" or "20201030160200_012".
55
+
56
+ show/update/delete reads its argument from the standard input when
57
+ no argument was passed in the command line.
58
+
59
+ version : print version
60
+ help : show help
61
+
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
47
67
  USAGE
48
68
  end
49
69
  end
@@ -64,9 +84,9 @@ USAGE
64
84
 
65
85
  puts case type
66
86
  when :file_system
67
- "#{base}/#{name}"
87
+ File.expand_path(name, base)
68
88
  else
69
- "#{base}/#{name}"
89
+ File.join(base, name)
70
90
  end
71
91
  end
72
92
  end
@@ -113,15 +133,16 @@ USAGE
113
133
  # :startdoc:
114
134
 
115
135
  class << self
136
+
116
137
  ##
117
138
  # Loads a class to perfom the command, then returns an instance
118
139
  # of the class.
119
140
  #
120
141
  # :call-seq:
121
- # "import" -> an object of Rbnotes::Commnads::Import
122
- # "list" -> an object of Rbnotes::Commands::List
123
- # "show" -> an object of Rbnotes::Commands::Show
124
- #
142
+ # load("import") -> Rbnotes::Commnads::Import
143
+ # load("list") -> Rbnotes::Commands::List
144
+ # load("show") -> Rbnotes::Commands::Show
145
+
125
146
  def load(cmd_name)
126
147
  cmd_name ||= DEFAULT_CMD_NAME
127
148
  klass_name = cmd_name.capitalize
@@ -9,7 +9,6 @@ module Rbnotes
9
9
  module ErrMsg
10
10
  MISSING_ARGUMENT = "missing argument: %s"
11
11
  MISSING_TIMESTAMP = "missing timestamp: %s"
12
- INVALID_TIMESTAMP_STRING = "invalid string as timestamp: %s"
13
12
  NO_EDITOR = "No editor is available: %s"
14
13
  PROGRAM_ABORT = "External program was aborted: %s"
15
14
  end
@@ -35,16 +34,6 @@ module Rbnotes
35
34
  end
36
35
  end
37
36
 
38
- ##
39
- # An error raised if an argument is invalid to convert a
40
- # Textrepo::Timestamp object.
41
-
42
- class InvalidTimestampStringError < Error
43
- def initialize(str)
44
- super(ErrMsg::INVALID_TIMESTAMP_STRING % str)
45
- end
46
- end
47
-
48
37
  ##
49
38
  # An error raised if no external editor is available to edit a note,
50
39
  # even "nano" or "vi".
@@ -96,11 +96,7 @@ module Rbnotes
96
96
 
97
97
  def read_timestamp(args)
98
98
  str = args.shift || read_arg($stdin)
99
- begin
100
- Textrepo::Timestamp.parse_s(str)
101
- rescue ArgumentError => _
102
- raise InvalidTimestampStringError, str
103
- end
99
+ Textrepo::Timestamp.parse_s(str)
104
100
  end
105
101
  module_function :read_timestamp
106
102
 
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.3.0"
3
- RELEASE = '2020-10-29'
2
+ VERSION = "0.3.1"
3
+ RELEASE = '2020-10-30'
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mnbi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo
@@ -56,6 +56,9 @@ files:
56
56
  - Rakefile
57
57
  - bin/console
58
58
  - bin/setup
59
+ - conf/config.yml
60
+ - conf/config_deve.yml
61
+ - conf/config_test.yml
59
62
  - exe/rbnotes
60
63
  - lib/rbnotes.rb
61
64
  - lib/rbnotes/commands.rb