Sha256: c91c766964c3b25de396ee18f4039a71d0694adf7c26a8a1827d3fd33d93acca

Contents?: true

Size: 1.88 KB

Versions: 47

Compression:

Stored size: 1.88 KB

Contents

# @@tags
desc 'List all tags in the current Doing file'
arg_name 'MAX_COUNT', optional: true, type: Integer
command :tags do |c|
  c.desc 'Section'
  c.arg_name 'SECTION_NAME'
  c.flag %i[s section], default_value: 'All'

  c.desc 'Show count of occurrences'
  c.switch %i[c counts]

  c.desc 'Output in a single line with @ symbols. Ignored if --counts is specified.'
  c.switch %i[l line]

  c.desc 'Sort by name or count'
  c.arg_name 'SORT_ORDER'
  c.flag %i[sort], default_value: 'name', must_match: /^(?:n(?:ame)?|c(?:ount)?)$/

  c.desc 'Sort order (asc/desc)'
  c.arg_name 'ORDER'
  c.flag %i[o order], must_match: REGEX_SORT_ORDER, default_value: :asc, type: OrderSymbol

  c.desc 'Select items to scan from a menu of matching entries'
  c.switch %i[i interactive], negatable: false, default_value: false

  add_options(:search, c)
  add_options(:tag_filter, c)

  c.action do |_global, options, args|
    section = @wwid.guess_section(options[:section]) || options[:section].cap_first
    options[:count] = args.count.positive? ? args[0].to_i : 0

    items = @wwid.filter_items([], opt: options)

    if options[:interactive]
      items = Doing::Prompt.choose_from_items(items, include_section: options[:section].nil?,
        menu: true,
        header: '',
        prompt: 'Select entries to scan > ',
        multiple: true,
        sort: true,
        show_if_single: true)
    end

    # items = @wwid.content.in_section(section)
    tags = @wwid.all_tags(items, counts: true)

    if options[:sort] =~ /^n/i
      tags = tags.sort_by { |tag, count| tag }
    else
      tags = tags.sort_by { |tag, count| count }
    end

    tags.reverse! if options[:order] == :desc

    if options[:counts]
      tags.each { |t, c| puts "#{t} (#{c})" }
    else
      if options[:line]
        puts tags.map { |t, c| t }.to_tags.join(' ')
      else
        tags.each { |t, c| puts "#{t}" }
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
doing-2.1.80 bin/commands/tags.rb
doing-2.1.79 bin/commands/tags.rb
doing-2.1.78 bin/commands/tags.rb
doing-2.1.77 bin/commands/tags.rb
doing-2.1.76 bin/commands/tags.rb
doing-2.1.75 bin/commands/tags.rb
doing-2.1.74 bin/commands/tags.rb
doing-2.1.73 bin/commands/tags.rb
doing-2.1.72 bin/commands/tags.rb
doing-2.1.69 bin/commands/tags.rb
doing-2.1.68 bin/commands/tags.rb
doing-2.1.66 bin/commands/tags.rb
doing-2.1.65 bin/commands/tags.rb
doing-2.1.64 bin/commands/tags.rb
doing-2.1.63 bin/commands/tags.rb
doing-2.1.62 bin/commands/tags.rb
doing-2.1.61 bin/commands/tags.rb
doing-2.1.60 bin/commands/tags.rb
doing-2.1.58 bin/commands/tags.rb
doing-2.1.57 bin/commands/tags.rb