rbnotes 0.4.11 → 0.4.16

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: 4170ccc84305971d10f3726351cdc4138b5fabaa7293bc10a827ed0458f28b8c
4
- data.tar.gz: 291efc32e2e65462e8c6996ecbbc7ffbb4e6887a5d0065bbb843d01dfbb8c78c
3
+ metadata.gz: a3f023516dcf1e39f18c6cd0195a548debfd635e23d476bdb7e89a6ddc5f981e
4
+ data.tar.gz: 52507a17c873c8732922e1cc5990fa41d74f36fca1f558fa5440090f3fcd9fe2
5
5
  SHA512:
6
- metadata.gz: 1f6d2659c1a50f462867a53bff3f7b45e8b38035c3af44407b70d359c6af9409481f1033059384bd8d6b42d03981ce4f955ac87ee5fe7e99f5b50465d47f4e1b
7
- data.tar.gz: f5949cfe44eef0951a80ec8949b6bb8a3440d5b483ddacdaf652d8b4dd258a7eb53db42c40290e9a2ebd6e3a1bf6e204f2382b41dd40b23ac8b271dd05547672
6
+ metadata.gz: '0946450a7eeda50688cc5dc836ce30e86d5db28e2af8dca8e84805026648ba018116e98d5b3d316339960a0273d1e717178c4832932418440e0db3c1d1b4e9a9'
7
+ data.tar.gz: 125c3c6fa116fc5cf13d82ba6fb522972b82364b61002de2adc6d36ab1f6d77051f89a948a7cc9ec28acce8179399b040bfc4d983e1c83c65bb2548cc44ee8eb
@@ -0,0 +1,18 @@
1
+ name: Build
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
data/.gitignore CHANGED
@@ -35,7 +35,6 @@ build-iPhoneSimulator/
35
35
  ## Documentation cache and generated files:
36
36
  /.yardoc/
37
37
  /_yardoc/
38
- /doc/
39
38
  /rdoc/
40
39
 
41
40
  ## Environment normalization:
data/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@ 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.16] - 2021-04-17
11
+ - Add a new configuration setting to change the default behavior of
12
+ the `list` (and `pick`) command. (#109)
13
+
14
+ ## [0.4.15] - 2021-04-15
15
+ - Enable to use delimiters within a timestamp string. (#104)
16
+ - Fix issue #105: `list` ignores the 2nd arg when specified `-w`
17
+ option.
18
+
19
+ ## [0.4.14] - 2021-04-10
20
+ - Add `-n` option to `show` command. (#102)
21
+ - Fix issue #100: modify to catch Textrepo::MissingTimestampError.
22
+
23
+ ## [0.4.13] - 2021-03-30
24
+ ### Changed
25
+ - Use GitHub/Actions instead of Travis-CI.
26
+ - Add `--week` option to `pick` command. (#88)
27
+
28
+ ### Fixed
29
+ - Fix issue #98: remove redundant args
30
+ (Rbnotes::Utils.read_multiple_timestamps). (#98)
31
+ - Update `textrepo`. -> 0.5.8 (#97)
32
+
33
+ ## [0.4.12] - 2020-12-18
34
+ ### Changed
35
+ - Make clear the spec of `list` command args. (#94)
36
+ - Add a feature to use a template file for `add` command. (#87)
37
+ - Add new keywords for `list` command. (#90)
38
+ - `this_month` and `last_month`
39
+ - Add a new option, `verbose` for `list` command. (#76)
40
+
41
+ ### Fixed
42
+ - Fix issue #80: suppress unnecessary error message.
43
+
8
44
  ## [0.4.11] - 2020-12-07
9
45
  ### Added
10
46
  - Add a new command `statistics`. (#73)
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ gemspec
6
6
  gem "rake", "~> 13.0"
7
7
  gem "minitest", "~> 5.0"
8
8
 
9
- gem 'textrepo', "~> 0.5.4"
9
+ gem 'textrepo', "~> 0.5.8"
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.11)
5
- textrepo (~> 0.5.4)
4
+ rbnotes (0.4.16)
5
+ textrepo (~> 0.5.8)
6
6
  unicode-display_width (~> 1.7)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- minitest (5.14.2)
12
- rake (13.0.1)
13
- textrepo (0.5.7)
11
+ minitest (5.14.4)
12
+ rake (13.0.3)
13
+ textrepo (0.5.8)
14
14
  unicode-display_width (1.7.0)
15
15
 
16
16
  PLATFORMS
@@ -20,7 +20,7 @@ DEPENDENCIES
20
20
  minitest (~> 5.0)
21
21
  rake (~> 13.0)
22
22
  rbnotes!
23
- textrepo (~> 0.5.4)
23
+ textrepo (~> 0.5.8)
24
24
 
25
25
  BUNDLED WITH
26
- 2.1.4
26
+ 2.2.15
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rbnotes
2
2
 
3
- [![Build Status](https://travis-ci.org/mnbi/rbnotes.svg?branch=main)](https://travis-ci.org/mnbi/rbnotes)
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
 
data/Rakefile CHANGED
@@ -25,6 +25,6 @@ require "rdoc/task"
25
25
 
26
26
  RDoc::Task.new do |rdoc|
27
27
  rdoc.generator = "ri"
28
- rdoc.rdoc_dir = "doc"
28
+ rdoc.rdoc_dir = "rdoc"
29
29
  rdoc.rdoc_files.include("lib/**/*.rb")
30
30
  end
data/conf/config.yml CHANGED
@@ -5,4 +5,5 @@
5
5
  :repository_base: "~"
6
6
  :pager: "bat -l md"
7
7
  :picker: "fzf"
8
+ :picker_option: "-m"
8
9
  :editor: "/usr/local/bin/emacsclient"
data/conf/config_deve.yml CHANGED
@@ -5,4 +5,5 @@
5
5
  :repository_base: "tmp"
6
6
  :pager: "bat -l md"
7
7
  :picker: "fzf"
8
+ :picker_option: "-m"
8
9
  :editor: "/usr/local/bin/emacsclient"
@@ -0,0 +1,8 @@
1
+ ---
2
+ :run_mode: :development
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "tmp"
6
+ :pager: "bat -l md"
7
+ :picker: "fzf"
8
+ :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,8 @@
1
+ ---
2
+ :run_mode: :development
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "tmp"
6
+ :pager: "bat -l md"
7
+ :picker: "peco"
8
+ :editor: "/usr/local/bin/emacsclient"
data/exe/rbnotes CHANGED
@@ -48,16 +48,24 @@ app = App.new
48
48
  begin
49
49
  app.parse_global_options(ARGV)
50
50
  app.run(ARGV)
51
- rescue Errno::EPIPE => e
51
+ rescue Errno::EPIPE => _
52
52
  # Fix issue #61: When the pipeline which rbnotes connects is
53
53
  # discarded by the other program, the execption was raised. It does
54
54
  # not end abnormally for rbnotes. So, just ignores the exception.
55
55
  exit 0
56
+ rescue NoArgumentError => _
57
+ # Fix issue #80: Typically, this error raises when a command tries
58
+ # to read the standard input for its arguments and gets nil. It
59
+ # means user wants to cancel to execute. So, just ignore the error
60
+ # and exit.
61
+ exit 0
56
62
  rescue MissingArgumentError, MissingTimestampError,
57
63
  NoEditorError, ProgramAbortError,
58
64
  Textrepo::InvalidTimestampStringError,
59
65
  InvalidTimestampPatternError,
66
+ InvalidTimestampPatternAsDateError,
60
67
  NoConfFileError,
68
+ NoTemplateFileError,
61
69
  ArgumentError,
62
70
  Errno::EACCES => e
63
71
  puts e.message
data/lib/rbnotes.rb CHANGED
@@ -10,9 +10,4 @@ module Rbnotes
10
10
  require_relative "rbnotes/commands"
11
11
  require_relative "rbnotes/statistics"
12
12
 
13
- class << self
14
- def utils
15
- Utils.instance
16
- end
17
- end
18
13
  end
@@ -34,19 +34,7 @@ module Rbnotes::Commands
34
34
 
35
35
  def execute(args, conf)
36
36
  @opts = {}
37
- while args.size > 0
38
- arg = args.shift
39
- case arg
40
- when "-t", "--timestamp"
41
- stamp_str = args.shift
42
- raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
43
- stamp_str = complement_timestamp_pattern(stamp_str)
44
- @opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
45
- else
46
- args.unshift(arg)
47
- break
48
- end
49
- end
37
+ parse_opts(args)
50
38
 
51
39
  stamp = @opts[:timestamp] || Textrepo::Timestamp.new(Time.now)
52
40
 
@@ -54,7 +42,8 @@ module Rbnotes::Commands
54
42
  editor = Rbnotes.utils.find_program(candidates)
55
43
  raise Rbnotes::NoEditorError, candidates if editor.nil?
56
44
 
57
- tmpfile = Rbnotes.utils.run_with_tmpfile(editor, stamp.to_s)
45
+ template = read_template(conf)
46
+ tmpfile = Rbnotes.utils.run_with_tmpfile(editor, stamp.to_s, template)
58
47
 
59
48
  unless FileTest.exist?(tmpfile)
60
49
  puts "Cancel adding, since nothing to store"
@@ -112,7 +101,28 @@ HELP
112
101
  end
113
102
 
114
103
  # :stopdoc:
104
+
115
105
  private
106
+
107
+ def parse_opts(args)
108
+ while args.size > 0
109
+ arg = args.shift
110
+ case arg
111
+ when "-t", "--timestamp"
112
+ stamp_str = args.shift
113
+ raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
114
+ stamp_str = complement_timestamp_pattern(stamp_str)
115
+ @opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
116
+ when "-f", "--template-file"
117
+ template_path = args.shift
118
+ @opts[:template] = template_path
119
+ else
120
+ args.unshift(arg)
121
+ break
122
+ end
123
+ end
124
+ end
125
+
116
126
  def complement_timestamp_pattern(pattern)
117
127
  stamp_str = nil
118
128
  case pattern.to_s.size
@@ -127,5 +137,26 @@ HELP
127
137
  end
128
138
  stamp_str
129
139
  end
140
+
141
+ def read_template(conf)
142
+ template = nil
143
+ template_path = @opts[:template] || conf[:template]
144
+
145
+ if template_path
146
+ raise Rbnotes::NoTemplateFileError, template_path unless FileTest.exist?(template_path)
147
+ template = File.readlines(template_path, chomp: true)
148
+ else
149
+ template_path = default_template_file(conf)
150
+ template = File.readlines(template_path, chomp: true) if FileTest.exist?(template_path)
151
+ end
152
+
153
+ template
154
+ end
155
+
156
+ def default_template_file(conf)
157
+ dir = File.join(conf[:config_home], "templates")
158
+ File.expand_path("default.md", dir)
159
+ end
160
+
130
161
  end
131
162
  end
@@ -12,18 +12,7 @@ module Rbnotes::Commands
12
12
 
13
13
  def execute(args, conf)
14
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
15
+ parse_opts(args)
27
16
 
28
17
  puts commands(@opts[:print_deve_commands]).join(" ")
29
18
  end
@@ -42,8 +31,24 @@ HELP
42
31
  end
43
32
 
44
33
  # :stopdoc:
34
+
45
35
  private
46
36
 
37
+ def parse_opts(args)
38
+ while args.size > 0
39
+ arg = args.shift
40
+ case arg.to_s
41
+ when "" # no options
42
+ break
43
+ when "-d", "--deve-commands"
44
+ @opts[:print_deve_commands] = true
45
+ else # invalid options or args
46
+ args.unshift(arg)
47
+ raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
48
+ end
49
+ end
50
+ end
51
+
47
52
  ##
48
53
  # Enumerates all command names.
49
54
  #
@@ -29,16 +29,7 @@ module Rbnotes::Commands
29
29
 
30
30
  def execute(args, conf)
31
31
  @opts = {}
32
- while args.size > 0
33
- arg = args.shift
34
- case arg
35
- when "-m", "--use-mtime"
36
- @opts[:use_mtime] = true
37
- else
38
- args.unshift(arg)
39
- break
40
- end
41
- end
32
+ parse_opts(args)
42
33
 
43
34
  file = args.shift
44
35
  unless file.nil?
@@ -116,5 +107,25 @@ If birthtime is not available on the system, use mtime (modification
116
107
  time).
117
108
  HELP
118
109
  end
110
+
111
+ # :stopdoc:
112
+
113
+ private
114
+
115
+ def parse_opts(args)
116
+ while args.size > 0
117
+ arg = args.shift
118
+ case arg
119
+ when "-m", "--use-mtime"
120
+ @opts[:use_mtime] = true
121
+ else
122
+ args.unshift(arg)
123
+ break
124
+ end
125
+ end
126
+ end
127
+
128
+ # :startdoc:
129
+
119
130
  end
120
131
  end
@@ -10,6 +10,8 @@ module Rbnotes::Commands
10
10
  "List notes"
11
11
  end
12
12
 
13
+ DEFAULT_BEHAVIOR = "today" # :nodoc:
14
+
13
15
  ##
14
16
  # Shows a list of notes in the repository. Arguments are
15
17
  # optional. If several args are passed, each of them must be a
@@ -24,10 +26,12 @@ module Rbnotes::Commands
24
26
  #
25
27
  # A keyword must be one of them:
26
28
  #
27
- # - "today" (or "to")
28
- # - "yeasterday" (or "ye")
29
- # - "this_week" (or "tw")
30
- # - "last_week" (or "lw")
29
+ # - "today" (or "to")
30
+ # - "yeasterday" (or "ye")
31
+ # - "this_week" (or "tw")
32
+ # - "last_week" (or "lw")
33
+ # - "this_month" (or "tm")
34
+ # - "last_month" (or "lm")
31
35
  #
32
36
  # Here is several examples of timestamp patterns.
33
37
  #
@@ -52,38 +56,35 @@ module Rbnotes::Commands
52
56
 
53
57
  def execute(args, conf)
54
58
  @opts = {}
55
- while args.size > 0
56
- arg = args.shift
57
- case arg
58
- when "-w", "--week"
59
- @opts[:enum_week] = true
60
- else
61
- args.unshift(arg)
62
- break
63
- end
64
- end
59
+ parse_opts(args)
65
60
 
66
- patterns = nil
67
- if @opts[:enum_week]
68
- arg = args.shift || Textrepo::Timestamp.now[0, 8]
69
- case arg.size
70
- when "yyyymodd".size, "yyyymoddhhmiss".size, "yyyymoddhhmiss_sfx".size
71
- stamp_str = "#{arg}000000"[0, 14]
72
- timestamp = Textrepo::Timestamp.parse_s(stamp_str)
73
- patterns = Rbnotes.utils.timestamp_patterns_in_week(timestamp)
74
- else
75
- raise InvalidTimestampPatternError,
76
- "cannot convert to a date [%s]" % args.unshift(arg)
77
- end
78
- else
79
- patterns = Rbnotes.utils.expand_keyword_in_args(args)
61
+ if args.empty?
62
+ default_behavior = conf[:list_default] || DEFAULT_BEHAVIOR
63
+ args << default_behavior
80
64
  end
81
65
 
66
+ utils = Rbnotes.utils
67
+ patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
68
+
82
69
  @repo = Textrepo.init(conf)
83
- # newer stamp shoud be above
84
- Rbnotes.utils.find_notes(patterns, @repo).each { |timestamp|
85
- puts Rbnotes.utils.make_headline(timestamp, @repo.read(timestamp))
86
- }
70
+ notes = utils.find_notes(patterns, @repo)
71
+ output = []
72
+ if @opts[:verbose]
73
+ collect_timestamps_by_date(notes).each { |date, timestamps|
74
+ output << "#{date} (#{timestamps.size})"
75
+ timestamps.each { |timestamp|
76
+ pad = " "
77
+ output << utils.make_headline(timestamp,
78
+ @repo.read(timestamp), pad)
79
+ }
80
+ }
81
+ else
82
+ notes.each { |timestamp|
83
+ output << utils.make_headline(timestamp,
84
+ @repo.read(timestamp))
85
+ }
86
+ end
87
+ puts output
87
88
  end
88
89
 
89
90
  def help # :nodoc:
@@ -110,6 +111,8 @@ KEYWORD:
110
111
  - "yeasterday" (or "ye")
111
112
  - "this_week" (or "tw")
112
113
  - "last_week" (or "lw")
114
+ - "this_month" (or "tm")
115
+ - "last_month" (or "lm")
113
116
 
114
117
  An option "--week" is also acceptable. It specifies to enumerate all
115
118
  days of a week. Typically, the option is used with a STAMP_PATTERN
@@ -124,5 +127,39 @@ would be as same as the KEYWORD, "this_week" was specified.
124
127
  HELP
125
128
  end
126
129
 
130
+ # :stopdoc:
131
+
132
+ private
133
+
134
+ def parse_opts(args)
135
+ while args.size > 0
136
+ arg = args.shift
137
+ case arg
138
+ when "-w", "--week"
139
+ @opts[:enum_week] = true
140
+ when "-v", "--verbose"
141
+ @opts[:verbose] = true
142
+ else
143
+ args.unshift(arg)
144
+ break
145
+ end
146
+ end
147
+ end
148
+
149
+ def collect_timestamps_by_date(timestamps)
150
+ result = {}
151
+ timestamps.map { |ts|
152
+ [ts.strftime("%Y-%m-%d"), ts]
153
+ }.reduce(result) { |r, pair|
154
+ date, stamp = pair
155
+ r[date] ||= []
156
+ r[date] << stamp
157
+ r
158
+ }
159
+ result
160
+ end
161
+
162
+ # :startdoc:
163
+
127
164
  end
128
165
  end