rubyshelltools 0.0.5 → 0.0.6

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.
@@ -7,7 +7,7 @@ rst --help
7
7
  Print out available options and commands
8
8
 
9
9
  $ rst --help
10
- Usage: rst [COMMAND [COMMAND ....]] [options] [FILES..]
10
+ Usage: rst [COMMAND] [options] [FILES..]
11
11
 
12
12
  Options:
13
13
  -v, --[no-]verbose Run verbosely
@@ -16,16 +16,28 @@ Print out available options and commands
16
16
  -f, --from DATE Set from-date
17
17
  -t, --to DATE Set to-date
18
18
  -n, --name NAME Use this name for the command
19
- -e, --new-event DATE,STRING Add an event
19
+ -e, --new-event [DATE,]STRING Add an event
20
20
  --list-calendars List available calendars
21
21
  --delete-calendar CALENDARNAME
22
22
  Delete an calendar and all it's entries!
23
23
  --[no-]empty Show empty entries
24
+ --save-defaults Save given params as defaults
25
+ --list-defaults list saved defaults
26
+ --clear-defaults delete previously saved defaults
27
+
24
28
  Commands:
25
29
  nil .......... no command. Interpret options only (useful in combination with -v)
26
30
  ls ........... list directory and files
27
31
  cal[endar] ... print a calendar --from --to
28
32
 
33
+ DATE-FORMATS FOR --new-event:
34
+ omitted....... today
35
+ today ........ today
36
+ nDWM ......... today + n days, weeks, months eg 1w, 2d[ays], 1M[ONTH]
37
+ yyyy-mm-dd
38
+ dd.mm.yyyy
39
+ mm/dd/yyyy
40
+
29
41
  use --example for a more detailed list of commands.
30
42
 
31
43
  rst ls *
@@ -59,11 +71,13 @@ overwrite this by defining env-vars for RST_DATA and RST_ENV
59
71
 
60
72
  $ export RST_DATA=$HOME/.rst/data
61
73
  $ export RST_ENV=production
74
+
62
75
  $ rst cal --new-event='1964-08-31,Birthday Andreas Altendorfer'
63
76
  $ rst cal -e 'today,Win the jackpot' # e is an abbreviation for --new-event
64
77
  $ rst cal -f 1964/1 # f is an abbreviation for --from
65
78
  Mon, Aug 31 1964: Birthday Andreas Altendorfer
66
79
  Fri, Mar 15 2013: Win the jackpot
80
+
67
81
  $ find $HOME/.rst
68
82
  /Users/you/.rst
69
83
  /Users/you/.rst/data
@@ -74,6 +88,8 @@ overwrite this by defining env-vars for RST_DATA and RST_ENV
74
88
  birthdays : 5 entries
75
89
  work : 2 entries
76
90
 
91
+ $ rst -e 1w,Some Event # entered on Tue, Jan 01 2013
92
+ Added: Tue, Jan 08 2013: Some Event
77
93
 
78
94
  The full set of parameters is
79
95
 
data/bin/rst CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
 
4
- require File.expand_path('../../rst', __FILE__)
5
4
  require_relative '../lib/rst'
6
5
  require_relative '../lib/load'
7
6
  include RST
@@ -51,7 +51,7 @@ module RST
51
51
  param
52
52
  elsif param =~ /today/i || param.nil?
53
53
  Date.today
54
- elsif param =~ /\d+[wmd]/i
54
+ elsif param =~ /\d+[a-zA-Z]/i
55
55
  get_today_plus(param)
56
56
  else
57
57
  Date.parse(param)
@@ -62,7 +62,7 @@ module RST
62
62
  # @param [String] param nDWM n=Number Day Weeks Months
63
63
  def get_today_plus(param)
64
64
  offset = 0
65
- param.scan(/(\d+)([dwm])/i) do |count,unit|
65
+ param.scan(/(\d+)([a-z])/i) do |count,unit|
66
66
  offset = case unit[0].downcase
67
67
  when 'd'
68
68
  count.to_i.days
@@ -145,9 +145,9 @@ module RST
145
145
  # @param [String|Date] end_on - output ends on this day
146
146
  # @param [Boolean] show_empty - output days with no events
147
147
  # @return [Array] of Strings DATE: EVENT + EVENT + ....
148
- def list_days(start_on=start_date,end_on=end_date,show_empty=false)
148
+ def list_days(start_on=start_date,end_on=end_date,show_empty=false,show_ids=false)
149
149
  (parse_date_param(start_on)..parse_date_param(end_on)).to_a.map { |_date|
150
- format_events_for(_date,show_empty)
150
+ format_events_for(_date,show_empty,show_ids)
151
151
  }.compact
152
152
  end
153
153
 
@@ -158,7 +158,16 @@ module RST
158
158
  def events_on(date)
159
159
  events.select { |event| event.event_date == date }
160
160
  end
161
-
161
+
162
+
163
+ # Dump calendar events
164
+ # @return [String]
165
+ def dump
166
+ events.map { |event|
167
+ '"%s,%s"' % [ event.event_date.strftime('%Y-%m-%d'), event.event_headline ]
168
+ }.join("\n")
169
+ end
170
+
162
171
  # @endgroup
163
172
 
164
173
  private
@@ -168,17 +177,25 @@ module RST
168
177
  # @param [Date] _date
169
178
  # @param [Boolean] show_empty - do output lines with no events
170
179
  # @return [String]
171
- def format_events_for(_date,show_empty=false)
172
- if (_line=event_headlines_for(_date)) != '' || show_empty
173
- "%s: %s" % [_date.strftime(DEFAULT_DATE_FORMAT), _line]
180
+ # @param [Boolean] show_ids - output ids for events
181
+ def format_events_for(_date,show_empty=false,show_ids=false)
182
+ if (_line=event_headlines_for(_date,show_ids)) != '' || show_empty
183
+ (show_ids ? "%s:\n %s" : "%s: %s") % [_date.strftime(DEFAULT_DATE_FORMAT), _line]
174
184
  end
175
185
  end
176
186
 
177
187
  # Concatenate headlines of all events on this date
178
188
  # @param [Date] _date
189
+ # @param [Boolean] _show_ids
179
190
  # @return [String]
180
- def event_headlines_for(_date)
181
- events_on(_date).map(&:event_headline).join(' + ').strip
191
+ def event_headlines_for(_date,_show_ids=false)
192
+ if !_show_ids
193
+ events_on(_date).map(&:event_headline).join(' + ').strip
194
+ else
195
+ events_on(_date).map{|e|
196
+ "%s > %s" % [e.respond_to?(:id) ? e.id : 'n/a' ,e.event_headline]
197
+ }.join("\n ").strip
198
+ end
182
199
  end
183
200
 
184
201
  # @endgroup
@@ -20,7 +20,7 @@ module RST
20
20
  #
21
21
  class CalendarEvent
22
22
 
23
- attr_reader :event_date, :label
23
+ attr_reader :event_date, :label, :id
24
24
 
25
25
  include Eventable
26
26
  include CalendarHelper
@@ -29,6 +29,7 @@ module RST
29
29
  # @param [String] _label - Events name
30
30
  def initialize(_date,_label)
31
31
  @label = _label
32
+ @id ||= SecureRandom::hex(4)
32
33
  schedule! ensure_date(_date)
33
34
  end
34
35
 
data/lib/rst.rb CHANGED
@@ -112,10 +112,22 @@ module RST
112
112
  @options[:delete_calendar] = name
113
113
  end
114
114
 
115
+ opts.on('--delete-events ID[,ID,...]',Array, 'delete entries from calendar') do |ids|
116
+ @options[:delete_events] = ids
117
+ end
118
+
115
119
  opts.on('--[no-]empty', 'Show empty entries') do |show|
116
120
  @options[:show_empty] = show
117
121
  end
118
122
 
123
+ opts.on('-i', '--with-ids', 'List entries with ids') do |ids|
124
+ @options[:with_ids] = ids
125
+ end
126
+
127
+ opts.on('-d', '--dump', 'Dump calendar-events' ) do |d|
128
+ @options[:dump] = d
129
+ end
130
+
119
131
  opts.on('--save-defaults', 'Save given params as defaults') do |v|
120
132
  @options[:save_defaults] = v
121
133
  end
@@ -128,20 +140,25 @@ module RST
128
140
  @options[:clear_defaults] = v
129
141
  end
130
142
 
143
+ opts.separator ''
131
144
  opts.separator 'Commands:'
132
145
 
133
146
  opts.separator <<-EOT
134
147
  nil .......... no command. Interpret options only (useful in combination with -v)
135
148
  ls ........... list directory and files
136
149
  cal[endar] ... print a calendar --from --to
150
+ EOT
151
+ .gsub(/^\s+/,' ')
137
152
 
138
- DATE-FORMATS FOR --new-event
139
- ommit ........ today
153
+ opts.separator ''
154
+ opts.separator 'DATE-FORMATS FOR --new-event:'
155
+ opts.separator <<-EOT
156
+ omitted....... today
140
157
  today ........ today
158
+ nDWM ......... today + n days, weeks, months eg 1w, 2d[ays], 1M[ONTH]
141
159
  yyyy-mm-dd
142
160
  dd.mm.yyyy
143
161
  mm/dd/yyyy
144
- nDWM ......... today + n days, weeks, months eg 1w, 2d[ays], 1M[ONTH]
145
162
  EOT
146
163
  .gsub(/^\s+/,' ')
147
164
 
@@ -203,7 +220,7 @@ module RST
203
220
  # @return [Array] - one string Date: Event + Event + ... for each day.
204
221
  def print_calendar
205
222
  cal = find_calendar( Persistent::DiskStore.new(CALENDAR_FILE) )
206
- cal.list_days(options[:from], options[:to], options[:show_empty]).compact.join("\n")
223
+ cal.list_days(options[:from], options[:to], options[:show_empty], options[:with_ids]).compact.join("\n")
207
224
  end
208
225
 
209
226
  # @group EXECUTE ACTION FROM OPTIONS
@@ -223,6 +240,10 @@ module RST
223
240
  "Added: %s: %s" % [new_event.event_date.strftime(DEFAULT_DATE_FORMAT), new_event.event_headline.strip]
224
241
  when 'list_calendars'
225
242
  list_calendars
243
+ when 'dump'
244
+ dump_calendar
245
+ when 'delete_events'
246
+ delete_events
226
247
  when 'delete_calendar'
227
248
  delete_calendar
228
249
  when 'save_defaults'
@@ -267,6 +288,27 @@ module RST
267
288
  }
268
289
  end
269
290
 
291
+ # Dump the calendar(s), thus the output can be used as input for -e again
292
+ # if no name-param is given all calendars are dumped.
293
+ # if name-param is given only the named calendar gets dumped.
294
+ # @return [String]
295
+ def dump_calendar
296
+ store = Persistent::DiskStore.new(CALENDAR_FILE)
297
+ store.all.map { |calendar|
298
+ calendar.dump if calendar.name == @options[:name] || @options[:name].blank?
299
+ }.compact.join("\n")
300
+ end
301
+
302
+ # Delete events with given IDs from calendar
303
+ # @example
304
+ # rst -n calname --delete-ids=34a4,44b3
305
+ def delete_events
306
+ store = Persistent::DiskStore.new(CALENDAR_FILE)
307
+ calendar = store.find(@options[:name])
308
+ calendar.events.reject!{|r| @options[:delete_events].include?(r.id)}
309
+ store << calendar
310
+ end
311
+
270
312
  # Output the previous interpreted and parsed arguments
271
313
  # Called when --verbose is given as an option
272
314
  # @example
data/rst.rb CHANGED
@@ -3,7 +3,7 @@ require 'logger'
3
3
  # # Ruby Shell Tools Top-level file
4
4
  module RST
5
5
  # Gem-version
6
- VERSION = '0.0.5'
6
+ VERSION = '0.0.6'
7
7
 
8
8
  # Path to the docs used by the software
9
9
  DOCS = File.expand_path('../assets/docs', __FILE__)
@@ -15,6 +15,10 @@ module RST
15
15
  # @see Persistent::DiskStore
16
16
  DEFAULT_STORE_FILENAME = 'rst_data.pstore'
17
17
 
18
+ # The length of an Eventable's id.
19
+ # @see Calendar::Eventable.id
20
+ EVENT_HEX_ID_LENGTH = 4
21
+
18
22
  # intialize the logger
19
23
  # @example Usage
20
24
  # RST.logger.info('This will output to STDERR')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyshelltools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redcarpet