doing 1.0.56 → 1.0.61

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a0efeeb7339da1578053099b2638ff6ca1e6319520a24b536381ca40a33e330
4
- data.tar.gz: e6507789ad1e43fce7e1627075fb4fc578f0a6c0630907ef78b469b05c09fc4d
3
+ metadata.gz: 406fa23f47c83c1b9b3c8fa1cd0e193761c0b13e7ec31f75fdf43b1375769d18
4
+ data.tar.gz: 2c7f30f6acfac0fb33266dd62ce204099c0358cef88e19de8f26c9e9a4f866f2
5
5
  SHA512:
6
- metadata.gz: 9914f2d9be6d9fbba69eaf67c316252186c712816e48cfb45acd7e278556f1e7769047b984a6e08fe8af36156d7bddb247f476685dcdbd3a375c28d4a0780172
7
- data.tar.gz: 53a81b430e70ceebf7f1d284d97a4579d0e29eea714a11380b1fa0dd526c98c2e94b9fef3edbc047e7f65b4df1c631d803840191d961738d2ed78e132ec72ba5
6
+ metadata.gz: 547c64a9fbfdb026a0ecaf1b4b0ae203306907ddbdc7cff76062b82312293e36eb170b8874f3aa643e19a8f2d3310aea472f23b12128b7b9eeb300956210ca68
7
+ data.tar.gz: 37d3819348c3167b6c77a34f8e7e2311015c3975e8595303e04c1d89cb28d7d8a83d7dfea810440b846621d90fd8e7bd1538dd9e3f607a2002284d1405474de8
data/README.md CHANGED
@@ -29,14 +29,10 @@ _Side note:_ I actually use the library behind this utility as part of another s
29
29
 
30
30
  ## Installation
31
31
 
32
- The current version of `doing` is <!--VER-->1.0.55<!--END VER-->.
32
+ The current version of `doing` is <!--VER-->1.0.60<!--END VER-->.
33
33
 
34
34
  $ [sudo] gem install doing
35
35
 
36
- To install the _latest_ version, use `--pre`:
37
-
38
- $ [sudo] gem install --pre doing
39
-
40
36
  Only use `sudo` if your environment requires it. If you're using the system Ruby on a Mac, for example, it will likely be necessary. If `gem install doing` fails, then run `sudo gem install doing` and provide your administrator password.
41
37
 
42
38
  Run `doing config` to open your `~/.doingrc` file in the editor defined in the `$EDITOR` environment variable. Set up your `doing_file` right away (where you want entries to be stored), and cover the rest after you've read the docs.
data/bin/doing CHANGED
@@ -572,7 +572,7 @@ command [:again, :resume] do |c|
572
572
 
573
573
  c.desc 'Boolean used to combine multiple tags'
574
574
  c.arg_name 'BOOLEAN'
575
- c.flag [:bool], must_match: /^(and|or|not)$/i, default_value: 'ALL'
575
+ c.flag [:bool], must_match: /^(and|or|not)$/i, default_value: 'AND'
576
576
 
577
577
  c.desc 'Note'
578
578
  c.arg_name 'TEXT'
@@ -1230,14 +1230,17 @@ desc 'Move entries between sections'
1230
1230
  arg_name 'SECTION_NAME'
1231
1231
  default_value wwid.current_section
1232
1232
  command :archive do |c|
1233
- c.desc 'Count to keep (ignored if archiving by tag)'
1234
- c.arg_name 'COUNT'
1235
- c.flag %i[k keep], default_value: 5, must_match: /^\d+$/, type: Integer
1233
+ c.desc 'How many items to keep (ignored if archiving by tag or search)'
1234
+ c.arg_name 'X'
1235
+ c.flag %i[k keep], must_match: /^\d+$/, type: Integer
1236
1236
 
1237
1237
  c.desc 'Move entries to'
1238
1238
  c.arg_name 'SECTION_NAME'
1239
1239
  c.flag %i[t to], default_value: 'Archive'
1240
1240
 
1241
+ c.desc 'Label moved items with @from(SECTION_NAME)'
1242
+ c.switch [:label], default_value: true, negatable: true
1243
+
1241
1244
  c.desc 'Tag filter, combine multiple tags with a comma. Added for compatibility with other commands.'
1242
1245
  c.arg_name 'TAG'
1243
1246
  c.flag [:tag]
@@ -1246,21 +1249,36 @@ command :archive do |c|
1246
1249
  c.arg_name 'BOOLEAN'
1247
1250
  c.flag [:bool], must_match: /(and|or|not)/i, default_value: 'AND'
1248
1251
 
1252
+ c.desc 'Search filter'
1253
+ c.arg_name 'QUERY'
1254
+ c.flag [:search]
1255
+
1249
1256
  c.action do |_global_options, options, args|
1250
1257
  if args.empty?
1251
1258
  section = wwid.current_section
1252
1259
  tags = []
1260
+ elsif args[0] =~ /^all/i
1261
+ section = 'all'
1253
1262
  elsif args[0] =~ /^@\S+/
1254
1263
  section = 'all'
1255
1264
  tags = args.map { |t| t.sub(/^@/, '').strip }
1256
1265
  else
1257
1266
  section = args[0].cap_first
1258
- tags = args.length > 1 ? args[1..].map { |t| t.sub(/^@/, '').strip } : nil
1267
+ tags = args.length > 1 ? args[1..].map { |t| t.sub(/^@/, '').strip } : []
1259
1268
  end
1260
1269
 
1270
+ raise '--keep and --count can\'t be used together' if options[:keep] && options[:count]
1271
+
1261
1272
  tags.concat(options[:tag].split(/ *, */).map { |t| t.sub(/^@/, '').strip }) if options[:tag]
1262
1273
 
1263
- wwid.archive(section, options[:keep], options[:to], tags, options[:bool])
1274
+ opts = {
1275
+ bool: options[:bool],
1276
+ destination: options[:to],
1277
+ keep: options[:keep],
1278
+ search: options[:search],
1279
+ tags: tags
1280
+ }
1281
+ wwid.archive(section, opts)
1264
1282
  end
1265
1283
  end
1266
1284
 
data/lib/doing/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Doing
2
- VERSION = '1.0.56'
2
+ VERSION = '1.0.61'
3
3
  end
data/lib/doing/wwid.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'deep_merge'
4
4
  require 'open3'
5
+ require 'pp'
5
6
 
6
7
  ##
7
8
  ## @brief Hash helpers
@@ -707,6 +708,11 @@ class WWID
707
708
  @results.push(%(No previous entry found))
708
709
  return
709
710
  end
711
+ unless last.has_tags?(['done'], 'ALL')
712
+ new_item = last.dup
713
+ new_item['title'] += " @done(#{Time.now.strftime('%F %R')})"
714
+ update_item(last, new_item)
715
+ end
710
716
  # Remove @done tag
711
717
  title = last['title'].sub(/\s*@done(\(.*?\))?/, '').chomp
712
718
  section = opt[:in].nil? ? last['section'] : guess_section(opt[:in])
@@ -736,8 +742,6 @@ class WWID
736
742
  end
737
743
  items = combined['items'].dup.sort_by { |item| item['date'] }.reverse
738
744
  sec_arr.push(items[0]['section'])
739
-
740
- sec_arr = sections
741
745
  else
742
746
  sec_arr = [guess_section(opt[:section])]
743
747
  end
@@ -800,12 +804,12 @@ class WWID
800
804
  if @content.key?(section)
801
805
 
802
806
  items = @content[section]['items'].dup.sort_by { |item| item['date'] }.reverse
803
- index = 0
807
+ idx = 0
804
808
  done_date = Time.now
805
809
  next_start = Time.now
806
810
  count = (opt[:count]).zero? ? items.length : opt[:count]
807
811
  items.map! do |item|
808
- break if index == count
812
+ break if idx == count
809
813
 
810
814
  tag_match = opt[:tag].nil? || opt[:tag].empty? ? true : item.has_tags?(opt[:tag], opt[:tag_bool])
811
815
  search_match = opt[:search].nil? || opt[:search].empty? ? true : item.matches_search?(opt[:search])
@@ -854,7 +858,7 @@ class WWID
854
858
  item['title'] = title
855
859
  end
856
860
 
857
- index += 1
861
+ idx += 1
858
862
  end
859
863
 
860
864
  item
@@ -886,6 +890,17 @@ class WWID
886
890
  write(@doing_file)
887
891
  end
888
892
 
893
+ def update_item(old_item, new_item)
894
+ section = old_item['section']
895
+
896
+ section_items = @content[section]['items']
897
+ s_idx = section_items.index(old_item)
898
+
899
+ section_items[s_idx] = new_item
900
+ @results.push("Entry updated: #{section_items[s_idx]['title']}")
901
+ @content[section]['items'] = section_items
902
+ end
903
+
889
904
  ##
890
905
  ## @brief Edit the last entry
891
906
  ##
@@ -1014,7 +1029,8 @@ class WWID
1014
1029
  # @param tag (String) Tag to replace
1015
1030
  # @param opt (Hash) Additional Options
1016
1031
  #
1017
- def stop_start(tag, opt = {})
1032
+ def stop_start(target_tag, opt = {})
1033
+ tag = target_tag.dup
1018
1034
  opt[:section] ||= @current_section
1019
1035
  opt[:archive] ||= false
1020
1036
  opt[:back] ||= Time.now
@@ -1535,31 +1551,24 @@ class WWID
1535
1551
  ## section
1536
1552
  ##
1537
1553
  ## @param section (String) The source section
1538
- ## @param count (Integer) The count
1539
- ## @param destination (String) The destination section
1540
- ## @param tags (Array) Tags to archive
1541
- ## @param bool (String) Tag boolean combinator
1554
+ ## @param options (Hash) Options
1542
1555
  ##
1543
- def archive(section = 'Currently', count = 5, destination = nil, tags = nil, bool = nil, _export = nil)
1556
+ def archive(section = 'Currently', options = {})
1557
+ count = options[:keep] || 0
1558
+ destination = options[:destination] || 'Archive'
1559
+ tags = options[:tags] || []
1560
+ bool = options[:bool] || 'AND'
1561
+
1544
1562
  section = choose_section if section.nil? || section =~ /choose/i
1545
- archive_all = section =~ /all/i # && !(tags.nil? || tags.empty?)
1563
+ archive_all = section =~ /^all$/i # && !(tags.nil? || tags.empty?)
1546
1564
  section = guess_section(section) unless archive_all
1547
1565
 
1548
- add_section('Archive') if destination =~ /archive/i && !sections.include?('Archive')
1566
+ add_section('Archive') if destination =~ /^archive$/i && !sections.include?('Archive')
1549
1567
 
1550
1568
  destination = guess_section(destination)
1551
1569
 
1552
1570
  if sections.include?(destination) && (sections.include?(section) || archive_all)
1553
- if archive_all
1554
- to_archive = sections.dup
1555
- to_archive.delete(destination)
1556
- to_archive.each do |source, _v|
1557
- do_archive(source, destination, { count: count, tags: tags, bool: bool, label: true })
1558
- end
1559
- else
1560
- do_archive(section, destination, { count: count, tags: tags, bool: bool, label: true })
1561
- end
1562
-
1571
+ do_archive(section, destination, { count: count, tags: tags, bool: bool, search: options[:search], label: options[:label] })
1563
1572
  write(doing_file)
1564
1573
  else
1565
1574
  raise 'Either source or destination does not exist'
@@ -1573,74 +1582,69 @@ class WWID
1573
1582
  ## @param destination (String) The destination section
1574
1583
  ## @param opt (Hash) Additional Options
1575
1584
  ##
1576
- def do_archive(section, destination, opt = {})
1577
- count = opt[:count] || 5
1578
- tags = opt[:tags] || []
1579
- bool = opt[:bool] || 'AND'
1580
- label = opt[:label] || false
1585
+ def do_archive(sect, destination, opt = {})
1586
+ count = opt[:count] || 0
1587
+ tags = opt[:tags] || []
1588
+ bool = opt[:bool] || 'AND'
1589
+ label = opt[:label] || true
1581
1590
 
1582
- items = @content[section]['items']
1583
- moved_items = []
1591
+ if sect =~ /^all$/i
1592
+ all_sections = sections.dup
1593
+ all_sections.delete(destination)
1594
+ else
1595
+ all_sections = [sect]
1596
+ end
1584
1597
 
1585
- if tags && !tags.empty?
1586
- items.delete_if do |item|
1587
- case bool
1588
- when /(AND|ALL)/i
1589
- score = 0
1590
- tags.each do |tag|
1591
- score += 1 if item['title'] =~ /@#{tag}/i
1592
- end
1593
- res = score < tags.length
1594
- moved_items.push(item) if res
1595
- res
1596
- when /NONE/i
1597
- del = false
1598
- tags.each do |tag|
1599
- del = true if item['title'] =~ /@#{tag}/i
1598
+ counter = 0
1599
+
1600
+ all_sections.each do |section|
1601
+ items = @content[section]['items']
1602
+
1603
+ moved_items = []
1604
+ if !tags.empty? || opt[:search]
1605
+ items.delete_if do |item|
1606
+ if (!tags.empty? && item.has_tags?(tags, bool) || (opt[:search] && item.matches_search?(opt[:search].to_s)))
1607
+ moved_items.push(item)
1608
+ counter += 1
1609
+ true
1610
+ else
1611
+ false
1600
1612
  end
1601
- moved_items.push(item) if del
1602
- del
1603
- when /(OR|ANY)/i
1604
- del = true
1605
- tags.each do |tag|
1606
- del = false if item['title'] =~ /@#{tag}/i
1613
+ end
1614
+ moved_items.each do |item|
1615
+ if label && section != 'Currently'
1616
+ item['title'] =
1617
+ item['title'].sub(/(?:@from\(.*?\))?(.*)$/, "\\1 @from(#{section})")
1607
1618
  end
1608
- moved_items.push(item) if del
1609
- del
1610
1619
  end
1611
- end
1612
- moved_items.each do |item|
1613
- if label && section != 'Currently'
1614
- item['title'] =
1615
- item['title'].sub(/(?:@from\(.*?\))?(.*)$/, "\\1 @from(#{section})")
1620
+
1621
+ @content[section]['items'] = items
1622
+ @content[destination]['items'].concat(moved_items)
1623
+ @results.push("Archived #{moved_items.length} items from #{section} to #{destination}")
1624
+ else
1625
+ count = items.length if count == 0 || items.length < count
1626
+
1627
+ @content[section]['items'] = if count.zero?
1628
+ []
1629
+ else
1630
+ items[0..count - 1]
1631
+ end
1632
+
1633
+ items.map! do |item|
1634
+ if label && section != 'Currently'
1635
+ item['title'] =
1636
+ item['title'].sub(/(?:@from\(.*?\))?(.*)$/, "\\1 @from(#{section})")
1637
+ end
1638
+ item
1616
1639
  end
1617
- end
1618
- @content[section]['items'] = moved_items
1619
- @content[destination]['items'] += items
1620
- @results.push("Archived #{items.length} items from #{section} to #{destination}")
1621
- else
1622
- count = items.length if items.length < count
1623
-
1624
- @content[section]['items'] = if count.zero?
1625
- []
1626
- else
1627
- items[0..count - 1]
1628
- end
1629
-
1630
- items.map! do |item|
1631
- if label && section != 'Currently'
1632
- item['title'] =
1633
- item['title'].sub(/(?:@from\(.*?\))?(.*)$/, "\\1 @from(#{section})")
1640
+ if items.count > count
1641
+ @content[destination]['items'].concat(items[count..-1])
1642
+ else
1643
+ @content[destination]['items'].concat(items)
1634
1644
  end
1635
- item
1636
- end
1637
- if items.count > count
1638
- @content[destination]['items'].concat(items[count..-1])
1639
- else
1640
- @content[destination]['items'].concat(items)
1641
- end
1642
1645
 
1643
- @results.push("Archived #{items.length - count} items from #{section} to #{destination}")
1646
+ @results.push("Archived #{items.length - count} items from #{section} to #{destination}")
1647
+ end
1644
1648
  end
1645
1649
  end
1646
1650
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.56
4
+ version: 1.0.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-06 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake