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 +4 -4
- data/README.md +1 -1
- data/bin/doing +23 -5
- data/lib/doing/version.rb +1 -1
- data/lib/doing/wwid.rb +65 -77
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 406fa23f47c83c1b9b3c8fa1cd0e193761c0b13e7ec31f75fdf43b1375769d18
|
4
|
+
data.tar.gz: 2c7f30f6acfac0fb33266dd62ce204099c0358cef88e19de8f26c9e9a4f866f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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 '
|
1234
|
-
c.arg_name '
|
1235
|
-
c.flag %i[k keep],
|
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 } :
|
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
|
-
|
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
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
|
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',
|
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 =~
|
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 =~
|
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
|
-
|
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(
|
1593
|
-
count = opt[:count] ||
|
1594
|
-
tags
|
1595
|
-
bool
|
1596
|
-
label = opt[:label] ||
|
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
|
-
|
1599
|
-
|
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
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
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
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
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
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
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
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
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
|
-
|
1646
|
+
@results.push("Archived #{items.length - count} items from #{section} to #{destination}")
|
1647
|
+
end
|
1660
1648
|
end
|
1661
1649
|
end
|
1662
1650
|
|