Sha256: 958a042978c1901b42c07d68beefa2af50ed79ec1322459c6891187cdfef9f6c

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

require_relative 'repository_command'
require 'json'

module Topicz::Commands

  class PathCommand < RepositoryCommand

    def initialize(config_file = nil, arguments = [])
      super(config_file)
      @strict = false
      option_parser.order! arguments
      @filter = arguments.join ' '
    end

    def option_parser
      OptionParser.new do |options|
        options.banner = 'Usage: path <filter>'
        options.on('-s', '--strict', 'Do a full strict match on topic IDs only') do
          @strict = true
        end
        options.separator ''
        options.separator 'Prints the absolute path to the topic that matches <filter>.'
        options.separator ''
        options.separator 'The filter specifies the text to search on. The text is matched against the topic\'s: '
        options.separator '- path on the filesystem'
        options.separator '- id, if specified in the topic\'s topic.yaml file'
        options.separator '- title, if specified in the topic\'s topic.yaml file'
        options.separator '- aliases, if specified in the topic\'s topic.yaml file'
        options.separator ''
        options.separator 'The filter must return precisely one topic. Zero or more matches give an error.'
      end
    end

    def execute
      print find_exactly_one_topic(@filter, @strict).fullpath
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
topicz-0.3.0 lib/topicz/commands/path_command.rb
topicz-0.2.0 lib/topicz/commands/path_command.rb
topicz-0.1.1 lib/topicz/commands/path_command.rb
topicz-0.1.0 lib/topicz/commands/path_command.rb