Class: Corrupt::Client

Inherits:
Object
  • Object
show all
Includes:
ClientHelpers
Defined in:
lib/corrupt/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClientHelpers

#error, #output, #take_action!

Constructor Details

#initialize(argv = ARGV) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/corrupt/client.rb', line 7

def initialize(argv = ARGV)
  @argv = argv
  @options = {}
end

Class Method Details

.runObject



12
13
14
# File 'lib/corrupt/client.rb', line 12

def self.run
  new.run
end

Instance Method Details

#runObject



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
# File 'lib/corrupt/client.rb', line 16

def run
  input = OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [options]"

    opts.on("--debug", "Turn on debugging output.") do |debug|
      $DEBUG = @options[:debug] = debug
    end

    opts.on("-n <path>", "--new", "Create a new Corrupt application.") do |path|
      @options[:path] = path
    end

    opts.on("-v", "--version", "Print the version.") do |v|
      output(Corrupt.to_version)
      exit
    end
  end

  begin
    @argv << '--help' if @argv.empty?
    input.parse!(@argv)
    take_action!
  rescue OptionParser::InvalidOption => error
    error("#{error}\nTry passing '--help'")
  rescue OptionParser::MissingArgument => error
    error("#{error}\nTry passing '--help'")
  end
end