doing 1.0.60 → 1.0.61

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: fd894959b5ebbff0cd1f08537ec0b754f5a1cc85bce8dbda3f59788ac4f0c230
4
- data.tar.gz: eb490a0bdaf48e7197dd1f2257d13142b6e2ec7629bf923aeb87a42c57dc0ec0
3
+ metadata.gz: 406fa23f47c83c1b9b3c8fa1cd0e193761c0b13e7ec31f75fdf43b1375769d18
4
+ data.tar.gz: 2c7f30f6acfac0fb33266dd62ce204099c0358cef88e19de8f26c9e9a4f866f2
5
5
  SHA512:
6
- metadata.gz: 762db76fac95e65bf0d684ac0f88d7ce7e0af7b22fd77792424d73f237d0501e111f4b2d892f74a6f7ca0564470f1a823c4f6843b1def0496502bf3f7f5d2ac0
7
- data.tar.gz: 9df0af7494c8a550119249dc6f30d5d6208e6adcea50dc1cd41b12749447eb042450eb29a144ef82a0235db99b71d4b5e0dc9aa23f331932be88cf157bb817b3
6
+ metadata.gz: 547c64a9fbfdb026a0ecaf1b4b0ae203306907ddbdc7cff76062b82312293e36eb170b8874f3aa643e19a8f2d3310aea472f23b12128b7b9eeb300956210ca68
7
+ data.tar.gz: 37d3819348c3167b6c77a34f8e7e2311015c3975e8595303e04c1d89cb28d7d8a83d7dfea810440b846621d90fd8e7bd1538dd9e3f607a2002284d1405474de8
data/README.md CHANGED
@@ -29,7 +29,7 @@ _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.59<!--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
 
data/bin/doing CHANGED
@@ -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.60'
2
+ VERSION = '1.0.61'
3
3
  end
data/lib/doing/wwid.rb CHANGED
@@ -1551,31 +1551,24 @@ class WWID
1551
1551
  ## section
1552
1552
  ##
1553
1553
  ## @param section (String) The source section
1554
- ## @param count (Integer) The count
1555
- ## @param destination (String) The destination section
1556
- ## @param tags (Array) Tags to archive
1557
- ## @param bool (String) Tag boolean combinator
1554
+ ## @param options (Hash) Options
1558
1555
  ##
1559
- 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
+
1560
1562
  section = choose_section if section.nil? || section =~ /choose/i
1561
- archive_all = section =~ /all/i # && !(tags.nil? || tags.empty?)
1563
+ archive_all = section =~ /^all$/i # && !(tags.nil? || tags.empty?)
1562
1564
  section = guess_section(section) unless archive_all
1563
1565
 
1564
- add_section('Archive') if destination =~ /archive/i && !sections.include?('Archive')
1566
+ add_section('Archive') if destination =~ /^archive$/i && !sections.include?('Archive')
1565
1567
 
1566
1568
  destination = guess_section(destination)
1567
1569
 
1568
1570
  if sections.include?(destination) && (sections.include?(section) || archive_all)
1569
- if archive_all
1570
- to_archive = sections.dup
1571
- to_archive.delete(destination)
1572
- to_archive.each do |source, _v|
1573
- do_archive(source, destination, { count: count, tags: tags, bool: bool, label: true })
1574
- end
1575
- else
1576
- do_archive(section, destination, { count: count, tags: tags, bool: bool, label: true })
1577
- end
1578
-
1571
+ do_archive(section, destination, { count: count, tags: tags, bool: bool, search: options[:search], label: options[:label] })
1579
1572
  write(doing_file)
1580
1573
  else
1581
1574
  raise 'Either source or destination does not exist'
@@ -1589,74 +1582,69 @@ class WWID
1589
1582
  ## @param destination (String) The destination section
1590
1583
  ## @param opt (Hash) Additional Options
1591
1584
  ##
1592
- def do_archive(section, destination, opt = {})
1593
- count = opt[:count] || 5
1594
- tags = opt[:tags] || []
1595
- bool = opt[:bool] || 'AND'
1596
- 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
1597
1590
 
1598
- items = @content[section]['items']
1599
- 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
1600
1597
 
1601
- if tags && !tags.empty?
1602
- items.delete_if do |item|
1603
- case bool
1604
- when /(AND|ALL)/i
1605
- score = 0
1606
- tags.each do |tag|
1607
- score += 1 if item['title'] =~ /@#{tag}/i
1608
- end
1609
- res = score < tags.length
1610
- moved_items.push(item) if res
1611
- res
1612
- when /NONE/i
1613
- del = false
1614
- tags.each do |tag|
1615
- 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
1616
1612
  end
1617
- moved_items.push(item) if del
1618
- del
1619
- when /(OR|ANY)/i
1620
- del = true
1621
- tags.each do |tag|
1622
- 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})")
1623
1618
  end
1624
- moved_items.push(item) if del
1625
- del
1626
1619
  end
1627
- end
1628
- moved_items.each do |item|
1629
- if label && section != 'Currently'
1630
- item['title'] =
1631
- 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
1632
1639
  end
1633
- end
1634
- @content[section]['items'] = moved_items
1635
- @content[destination]['items'] += items
1636
- @results.push("Archived #{items.length} items from #{section} to #{destination}")
1637
- else
1638
- count = items.length if items.length < count
1639
-
1640
- @content[section]['items'] = if count.zero?
1641
- []
1642
- else
1643
- items[0..count - 1]
1644
- end
1645
-
1646
- items.map! do |item|
1647
- if label && section != 'Currently'
1648
- item['title'] =
1649
- 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)
1650
1644
  end
1651
- item
1652
- end
1653
- if items.count > count
1654
- @content[destination]['items'].concat(items[count..-1])
1655
- else
1656
- @content[destination]['items'].concat(items)
1657
- end
1658
1645
 
1659
- @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
1660
1648
  end
1661
1649
  end
1662
1650
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.60
4
+ version: 1.0.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra