rbnotes 0.2.2 → 0.3.0

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: 74c8725b48ee7e4048c6689227e519e27490e604463f84822211b0bad0bf8849
4
- data.tar.gz: 71ef7e862a20d309c2c8fb29dc54ddacd42f6c3ab1f2eefd2e1dfb17e6ca8b2b
3
+ metadata.gz: 906c366a81295b7d9a1c2e86ad2bd6f1d35f410ac7360f1e2067c0a0f8e4f48b
4
+ data.tar.gz: d2af84cbd9ddbb60fe6f21ddffb9c072ebe0b767e8c8ab6ae4cac0c1bca30acd
5
5
  SHA512:
6
- metadata.gz: b3310eae55fd1bc5e5b8a9b83a0ba5ae7f76e3d953a8a94f62fb7aabd9952ff03f868328e4b1e978b9c80a9c9b3563b676fc10eb776dbb47051bb1026fcad765
7
- data.tar.gz: 36e328b4a3a6fe64f52c52f31050c46b372f91e2f768420b235c1ed811908634e80197aa7cf358cc87e434f57cba61fcbefa76a0aa61633e119d70f3502a9997
6
+ metadata.gz: 5fa3929995ebda0b4970c18516dadc37b5ddeb99d2a33c39ce90ac9f8bb90556c7a406b995b3373e4bc559c56b57750f0a0796f53b3d25624d1a891d2da456d1
7
+ data.tar.gz: 99c4dd49875b4cf1f262cbd845bbccb6482449f0a1573ed188b50cd6814c1220cc7cea1032cc2b6bbaaeb2e05c4f21f8a241e8931ff8d44128e72f8457c1b113
@@ -7,8 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
+ ## [0.3.0] - 2020-10-29
11
+ ### Added
12
+ - Add feature to read argument from the standard input. (#27)
13
+
10
14
  ## [0.2.2] - 2020-10-27
11
- ###
15
+ ### Added
12
16
  - Add feature to accept a timestamp pattern in `list` command. (#22)
13
17
 
14
18
  ## [0.2.1] - 2020-10-25
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.2.2)
4
+ rbnotes (0.3.0)
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.3)
13
+ textrepo (0.4.4)
14
14
  unicode-display_width (1.7.0)
15
15
 
16
16
  PLATFORMS
@@ -17,7 +17,7 @@ app = App.new
17
17
  begin
18
18
  app.run(ARGV)
19
19
  rescue MissingArgumentError, MissingTimestampError,
20
- NoEditorError, ProgramAbortError => e
20
+ InvalidTimestampStringError, NoEditorError, ProgramAbortError => e
21
21
  puts e.message
22
22
  exit 1
23
23
  end
@@ -14,21 +14,17 @@
14
14
  module Rbnotes
15
15
  class Commands::Delete < Commands::Command
16
16
  def execute(args, conf)
17
- stamp_str = args.shift
18
- unless stamp_str.nil?
19
- repo = Textrepo.init(conf)
20
- begin
21
- stamp = Textrepo::Timestamp.parse_s(stamp_str)
22
- repo.delete(stamp)
23
- rescue Textrepo::MissingTimestampError => e
24
- puts e.message
25
- rescue StandardError => e
26
- puts e.message
27
- else
28
- puts "Delete [%s]" % stamp.to_s
29
- end
17
+ stamp = Rbnotes::Utils.read_timestamp(args)
18
+
19
+ repo = Textrepo.init(conf)
20
+ begin
21
+ repo.delete(stamp)
22
+ rescue Textrepo::MissingTimestampError => e
23
+ puts e.message
24
+ rescue StandardError => e
25
+ puts e.message
30
26
  else
31
- super
27
+ puts "Delete [%s]" % stamp.to_s
32
28
  end
33
29
  end
34
30
  end
@@ -29,7 +29,7 @@ module Rbnotes
29
29
  puts "The note [%s] in the repository exactly matches" \
30
30
  " the specified file." % stamp
31
31
  puts "It seems there is no need to import the file [%s]." % file
32
- exit # normal end
32
+ break
33
33
  else
34
34
  puts "The text in the repository does not match the" \
35
35
  " specified file."
@@ -40,8 +40,8 @@ module Rbnotes
40
40
  end
41
41
  rescue Textrepo::EmptyTextError => _
42
42
  puts "... aborted."
43
- puts "The specified file is empyt."
44
- exit 1 # error
43
+ puts "The specified file is empty."
44
+ break
45
45
  end
46
46
  end
47
47
  if count > 999
@@ -54,11 +54,11 @@ module Rbnotes
54
54
  # Makes a headline with the timestamp and subject of the notes, it
55
55
  # looks like as follows:
56
56
  #
57
- # |<------------------ console column size --------------------->|
58
- # +-- timestamp ---+ +--- subject (the 1st line of each note) --+
59
- # | | | |
60
- # 20101010001000_123: # I love Macintosh. [EOL]
61
- # 20100909090909_999: # This is very very long long loooong subje[EOL]
57
+ # |<------------------ console column size ------------------->|
58
+ # +-- timestamp ---+ +- subject (the 1st line of each note) -+
59
+ # | | | |
60
+ # 20101010001000_123: I love Macintosh. [EOL]
61
+ # 20100909090909_999: This is very very long long loooong subje[EOL]
62
62
  # ++
63
63
  # ^--- delimiter (2 characters)
64
64
  #
@@ -69,9 +69,7 @@ module Rbnotes
69
69
  delimiter = ": "
70
70
  subject_width = column - TIMESTAMP_STR_MAX_WIDTH - delimiter.size - 1
71
71
 
72
- subject = @repo.read(timestamp)[0]
73
- prefix = '# '
74
- subject = prefix + subject.lstrip if subject[0, 2] != prefix
72
+ subject = remove_heading_markup(@repo.read(timestamp)[0])
75
73
 
76
74
  ts_part = "#{timestamp.to_s} "[0..(TIMESTAMP_STR_MAX_WIDTH - 1)]
77
75
  sj_part = truncate_str(subject, subject_width)
@@ -90,6 +88,10 @@ module Rbnotes
90
88
  result
91
89
  end
92
90
 
91
+ def remove_heading_markup(str)
92
+ str.sub(/^#+ +/, '')
93
+ end
94
+
93
95
  # :startdoc:
94
96
  end
95
97
  end
@@ -1,24 +1,20 @@
1
1
  module Rbnotes
2
2
  class Commands::Show < Commands::Command
3
3
  def execute(args, conf)
4
- stamp_str = args.shift
5
- unless stamp_str.nil?
6
- repo = Textrepo.init(conf)
7
- stamp = Textrepo::Timestamp.parse_s(stamp_str)
8
- content = repo.read(stamp)
4
+ stamp = Rbnotes::Utils.read_timestamp(args)
9
5
 
10
- pager = conf[:pager]
11
- unless pager.nil?
12
- require 'open3'
13
- Open3.pipeline_w(pager) { |stdin|
14
- stdin.puts content
15
- stdin.close
16
- }
17
- else
18
- puts content
19
- end
6
+ repo = Textrepo.init(conf)
7
+ content = repo.read(stamp)
8
+
9
+ pager = conf[:pager]
10
+ unless pager.nil?
11
+ require 'open3'
12
+ Open3.pipeline_w(pager) { |stdin|
13
+ stdin.puts content
14
+ stdin.close
15
+ }
20
16
  else
21
- super
17
+ puts content
22
18
  end
23
19
  end
24
20
  end
@@ -19,7 +19,7 @@ module Rbnotes::Commands
19
19
  # as add command.
20
20
  #
21
21
  # If none of editors is available, the command fails.
22
- #
22
+
23
23
  class Update < Command
24
24
  include ::Rbnotes::Utils
25
25
 
@@ -30,19 +30,10 @@ module Rbnotes::Commands
30
30
  #
31
31
  # :call-seq:
32
32
  # "20201020112233" -> "20201021123400"
33
- #
34
- def execute(args, conf)
35
- raise Rbnotes::MissingArgumentError, args if args.size < 1
36
-
37
- target_stamp = nil
38
- begin
39
- target_stamp = Textrepo::Timestamp.parse_s(args.shift)
40
- rescue ArgumentError => e
41
- raise Rbnotes::MissingArgumentError, args
42
- end
43
33
 
34
+ def execute(args, conf)
35
+ target_stamp = Rbnotes::Utils.read_timestamp(args)
44
36
  editor = find_editor(conf[:editor])
45
-
46
37
  repo = Textrepo.init(conf)
47
38
 
48
39
  text = nil
@@ -1,13 +1,15 @@
1
1
  module Rbnotes
2
2
  ##
3
3
  # A base class for each error class of rbnotes.
4
- #
4
+
5
5
  class Error < StandardError; end
6
6
 
7
7
  # :stopdoc:
8
+
8
9
  module ErrMsg
9
10
  MISSING_ARGUMENT = "missing argument: %s"
10
11
  MISSING_TIMESTAMP = "missing timestamp: %s"
12
+ INVALID_TIMESTAMP_STRING = "invalid string as timestamp: %s"
11
13
  NO_EDITOR = "No editor is available: %s"
12
14
  PROGRAM_ABORT = "External program was aborted: %s"
13
15
  end
@@ -16,7 +18,7 @@ module Rbnotes
16
18
 
17
19
  ##
18
20
  # An error raised if an essential argument was missing.
19
- #
21
+
20
22
  class MissingArgumentError < Error
21
23
  def initialize(args)
22
24
  super(ErrMsg::MISSING_ARGUMENT % args.to_s)
@@ -26,17 +28,27 @@ module Rbnotes
26
28
  ##
27
29
  # An error raised if a given timestamp was not found in the
28
30
  # repository.
29
- #
31
+
30
32
  class MissingTimestampError < Error
31
33
  def initialize(timestamp)
32
34
  super(ErrMsg::MISSING_TIMESTAMP % timestamp)
33
35
  end
34
36
  end
35
37
 
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
+
36
48
  ##
37
49
  # An error raised if no external editor is available to edit a note,
38
50
  # even "nano" or "vi".
39
- #
51
+
40
52
  class NoEditorError < Error
41
53
  def initialize(names)
42
54
  super(ErrMsg::NO_EDITOR % names.to_s)
@@ -46,6 +58,7 @@ module Rbnotes
46
58
  ##
47
59
  # An error raised when a external program such an editor was aborted
48
60
  # during its execution.
61
+
49
62
  class ProgramAbortError < Error
50
63
  def initialize(cmdline)
51
64
  super(ErrMsg::PROGRAM_ABORT % cmdline.join(" "))
@@ -86,6 +86,41 @@ module Rbnotes
86
86
  end
87
87
  module_function :run_with_tmpfile
88
88
 
89
+ ##
90
+ # Generates a Textrepo::Timestamp object from a String which comes
91
+ # from the command line arguments. When no argument is given,
92
+ # then reads from STDIN.
93
+ #
94
+ # :call-seq:
95
+ # read_timestamp(args) -> String
96
+
97
+ def read_timestamp(args)
98
+ str = args.shift || read_arg($stdin)
99
+ begin
100
+ Textrepo::Timestamp.parse_s(str)
101
+ rescue ArgumentError => _
102
+ raise InvalidTimestampStringError, str
103
+ end
104
+ end
105
+ module_function :read_timestamp
106
+
107
+ ##
108
+ # Reads an argument from the IO object. Typically, it is intended
109
+ # to be used with STDIN.
110
+ #
111
+ # :call-seq:
112
+ # read_arg(IO) -> String
113
+
114
+ def read_arg(io)
115
+ # assumes the reading line looks like:
116
+ #
117
+ # foo bar baz ...
118
+ #
119
+ # then, only the first string is interested
120
+ io.gets.split(" ")[0]
121
+ end
122
+ module_function :read_arg
123
+
89
124
  # :stopdoc:
90
125
 
91
126
  private
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.2.2"
3
- RELEASE = '2020-10-27'
2
+ VERSION = "0.3.0"
3
+ RELEASE = '2020-10-29'
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.2.2
4
+ version: 0.3.0
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-27 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo