Class: YTools::Path::CLI

Inherits:
BaseCLI show all
Defined in:
lib/ytools/path/cli.rb

Instance Method Summary collapse

Methods inherited from BaseCLI

#execute!, #initialize, #parse

Constructor Details

This class inherits a constructor from YTools::BaseCLI

Instance Method Details

#commandObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ytools/path/cli.rb', line 9

def command
  Choosy::Command.new :ypath do
    printer :standard, :max_width => 80
    executor Executor.new

    heading 'Description:'
    para "This tool uses a kind of XPath syntax for locating and printing elements from within YAML files.  Check out the '--examples' flag for details on the exact path syntax."
    para "It accepts multiple yaml files, and will merge their contents in the order in which they are given.  Thus, files listed later, if their keys conflict with ones listed earlier, override the earlier listed values.  If you pass in files that don't exist, no error will be  raised unless the '--strict' flag is passed."

    heading 'Option:'
    string :path, "The YAML Path pattern syntax to run against the input." do
      required
      depends_on :examples
      validate do |path, options|
        begin
          options[:selector] = YTools::Path::Parser.new(path).parse!
        rescue YTools::Path::ParseError => e
          if e.token.path == ""
            die "error parsing expression: #{e.message}"
          else
            die "error parsing expression: #{e.message}
#{e.token.path}
#{' ' * e.token.offset}^"
          end
        end
      end
    end
  end
end