Class: GhSearch::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/gh_search/cli.rb

Class Method Summary collapse

Class Method Details

.startObject



6
7
8
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gh_search/cli.rb', line 6

def self.start
  opts = GetoptLong.new(
    [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
    [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
    [ '--org', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--file', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--lang', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--output', '-o', GetoptLong::REQUIRED_ARGUMENT ],
  )


  options = {}

  begin
    opts.each do |opt, arg|
      case opt
      when '--help'
        print_help
        exit 0
      when '--version'
        puts "gh-search #{GhSearch::VERSION}"
        exit 0
      when '--org'
        options[:org] = arg
      when '--lang'
        options[:lang] = arg
      when '--file'
        options[:file] = arg
      when '--format'
        options[:format ]= arg
      when '--output'
        options[:output] = arg
      end
    end
  rescue GetoptLong::Error => e
    print_help
    exit 1
  end
  if ARGV.length != 1
    puts "Missing SEARCH_TEXT argument (try --help)"
    puts
    print_help
    exit 0
  end

  search_text = ARGV.shift

  GhSearch.run(search_text, options)
end