rbnotes 0.4.13 → 0.4.14

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: 55b7ddb12d306be2cb815400d4e729deff8badfbde55ede0f9edba78c380eb44
4
- data.tar.gz: ae0720108810db518693959f3a8faf20c7ca985d6aaf3c39bac94327d45f25db
3
+ metadata.gz: 21771aaf2f868b68cafa9e3643540a8bae49a96ce3662038c49d3a5053b37b04
4
+ data.tar.gz: c91cd115792241d9f441efd93c56305c7b0c97dc02ece0f411ee73277f6bfd82
5
5
  SHA512:
6
- metadata.gz: 8fc47bdc0c93bc964714c89d791655f1d385de0dfbf6af5202ec18c17f1be951efb02fcd4d9b0ac9b298cbb163e8a9e836a5c4d752bf9bad5299cc0d38983463
7
- data.tar.gz: d2a3db96531609429775b9caf32308691afc6023ffaf2d8aae39df3d763e99b497a3efe763e821033ab725240e925ddd23a5385dac15d0a3bd5f3cb9f7c23ac1
6
+ metadata.gz: 4bd54a316a4b8461ba93126cffbd2e154fc6231395b8ee7c792c2aeb941cc710ac4f2e4e5b75eb3d902cc5cccb32bd412bfc2b7418b2ab1d9d00173ced928360
7
+ data.tar.gz: 1a600b848a559c743789ac1a55f8fcc932da10a063b4d25e31c04d2af94d79c346368271d86a2565fb1d325659c8cf5acbb588a53ac27b227c990d5cce801889
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
+ - Nothing to record here.
9
+
10
+ ## [0.4.14] - 2021-04-10
11
+ - Add `-n` option to `show` command. (#102)
12
+ - Fix issue #100: modify to catch Textrepo::MissingTimestampError.
8
13
 
9
14
  ## [0.4.13] - 2021-03-30
10
15
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.13)
4
+ rbnotes (0.4.14)
5
5
  textrepo (~> 0.5.8)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -23,4 +23,4 @@ DEPENDENCIES
23
23
  textrepo (~> 0.5.8)
24
24
 
25
25
  BUNDLED WITH
26
- 2.2.3
26
+ 2.2.15
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rbnotes
2
2
 
3
3
  [![Build Status](https://github.com/mnbi/rbnotes/workflows/Build/badge.svg)](https://github.com/mnbi/rbnotes/actions?query=workflow%3A"Build")
4
+ [![CodeFactor](https://www.codefactor.io/repository/github/mnbi/rbnotes/badge)](https://www.codefactor.io/repository/github/mnbi/rbnotes)
4
5
 
5
6
  Rbnotes is a simple utility to write a note in the single repository.
6
7
 
@@ -5,13 +5,17 @@ module Rbnotes::Commands
5
5
  # argument must be a string which can be converted into
6
6
  # Textrepo::Timestamp object.
7
7
  #
8
+ # Accepts an option with `-n NUMBER` (or `--num-of-lines`), to show
9
+ # the first NUMBER lines of the content of each note.
10
+ #
8
11
  # A string for Textrepo::Timestamp must be:
9
12
  #
10
13
  # "20201106112600" : year, date, time and sec
11
14
  # "20201106112600_012" : with suffix
12
15
  #
13
16
  # If no argument is passed, reads the standard input for arguments.
14
-
17
+ # If a specified timestamp does not exist in the repository as a key,
18
+ # Rbnotes::MissingTimestampError will occur.
15
19
  class Show < Command
16
20
 
17
21
  def description # :nodoc:
@@ -19,10 +23,26 @@ module Rbnotes::Commands
19
23
  end
20
24
 
21
25
  def execute(args, conf)
26
+ @opts = {}
27
+ parse_opts(args)
28
+
22
29
  stamps = Rbnotes.utils.read_multiple_timestamps(args)
23
30
  repo = Textrepo.init(conf)
24
31
 
25
- content = stamps.map { |stamp| [stamp, repo.read(stamp)] }.to_h
32
+ content = stamps.map { |stamp|
33
+ begin
34
+ text = repo.read(stamp)
35
+ rescue Textrepo::MissingTimestampError => _
36
+ raise Rbnotes::MissingTimestampError, stamp
37
+ end
38
+
39
+ lines = text.size
40
+ if @opts[:num_of_lines].to_i > 0
41
+ lines = [@opts[:num_of_lines], lines].min
42
+ end
43
+
44
+ [stamp, text[0, lines]]
45
+ }.to_h
26
46
 
27
47
  pager = conf[:pager]
28
48
  unless pager.nil?
@@ -35,11 +55,14 @@ module Rbnotes::Commands
35
55
  def help # :nodoc:
36
56
  puts <<HELP
37
57
  usage:
38
- #{Rbnotes::NAME} show [TIMESTAMP...]
58
+ #{Rbnotes::NAME} show [(-n|--num-of-lines) NUMBER] [TIMESTAMP...]
39
59
 
40
60
  Show the content of given notes. TIMESTAMP must be a fully qualified
41
61
  one, such "20201016165130" or "20201016165130_012" if it has a suffix.
42
62
 
63
+ Accept an option with `-n NUMBER` (or `--num-of-lines`), to show the
64
+ first NUMBER lines of the content of each note.
65
+
43
66
  The command try to read its argument from the standard input when no
44
67
  argument was passed in the command line.
45
68
  HELP
@@ -49,6 +72,25 @@ HELP
49
72
 
50
73
  private
51
74
 
75
+ def parse_opts(args)
76
+ while args.size > 0
77
+ arg = args.shift
78
+ case arg
79
+ when "-n", "--num-of-lines"
80
+ num_of_lines = args.shift
81
+ raise ArgumentError, "missing number: %s" % args.unshift(arg) if num_of_lines.nil?
82
+
83
+ num_of_lines = num_of_lines.to_i
84
+ raise ArgumentError, "illegal number (must be greater than 0): %d" % num_of_lines unless num_of_lines > 0
85
+
86
+ @opts[:num_of_lines] = num_of_lines
87
+ else
88
+ args.unshift(arg)
89
+ break
90
+ end
91
+ end
92
+ end
93
+
52
94
  def puts_with_pager(pager, output)
53
95
  require "open3"
54
96
  Open3.pipeline_w(pager) { |stdin|
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.13"
3
- RELEASE = "2021-03-30"
2
+ VERSION = "0.4.14"
3
+ RELEASE = "2021-04-10"
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.13
4
+ version: 0.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - mnbi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.2.3
109
+ rubygems_version: 3.2.15
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: A simple utility to write a note.