Module: Zendesk::CommandLine

Extended by:
CommandLine
Included in:
CommandLine
Defined in:
lib/zendesk/command_line.rb

Constant Summary collapse

HELP_TEXT =
<<~TXT

  examples:
      
    # search field "_id" for value equal to "101" in "organizations.json".
    zendesk --command _id=101 --files data/organizations.json
      
    # search field "domain_names" for value equal to "zentix.com" using default fixtures.
    zendesk --command domain_names=zentix.com
      
    # search with multiple command expressions.
    zendesk --command "_id=101 _id=102" --files data/organizations.json
      
    # search with multiple file paths.
    zendesk --command "_id=101" --files data/organizations.json --files data/users.json

TXT

Instance Method Summary collapse

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zendesk/command_line.rb', line 31

def run
  opts = Slop.parse do |opts|
    opts.array '-f', '--files', '"path/to/file.json"', default: default_file_paths
    opts.string '-c', '--command', '"<FIELD>=<VALUE>"', required: true
    opts.string '-s', '--strategy', '"ruby", "sqlite3" supported', default: 'ruby'
    opts.string '-p', '--printer', '"table", "json" supported', default: 'table'

    opts.on '-h', '--help' do
      puts opts

      puts HELP_TEXT

      exit
    end

    opts.on '--version', 'print the version' do
      puts Zendesk::VERSION

      exit
    end


  end

  results = Zendesk::Processor.process(opts[:command], opts[:files], opts[:strategy])

  Zendesk::Printer.get(opts[:printer]).print(results)
rescue Exception => e
  puts e.message

  exit
end