rbnotes 0.4.13 → 0.4.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -0
- data/lib/rbnotes/commands/show.rb +45 -3
- data/lib/rbnotes/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21771aaf2f868b68cafa9e3643540a8bae49a96ce3662038c49d3a5053b37b04
|
4
|
+
data.tar.gz: c91cd115792241d9f441efd93c56305c7b0c97dc02ece0f411ee73277f6bfd82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Rbnotes
|
2
2
|
|
3
3
|
[](https://github.com/mnbi/rbnotes/actions?query=workflow%3A"Build")
|
4
|
+
[](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|
|
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|
|
data/lib/rbnotes/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|