Class: Tracetool::ParseArgs

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

Overview

Tracetool cli args parser

Constant Summary collapse

ARCH_LIST =

List of supported abis. Only needed for iOS unpacking

%i[arm arm64].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults, io) ⇒ ParseArgs

Returns a new instance of ParseArgs.



44
45
46
47
48
# File 'lib/tracetool/utils/cli.rb', line 44

def initialize(defaults, io)
  @io = io
  @options = defaults
  @opt_parser = gen_opt_parser
end

Class Method Details

.check(options) ⇒ Object



38
39
40
41
42
# File 'lib/tracetool/utils/cli.rb', line 38

def self.check(options)
  {
    'platform' => options.platform
  }.each { |arg, check| raise(OptionParser::MissingArgument, arg) unless check }
end

.check_ios(options) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/tracetool/utils/cli.rb', line 28

def self.check_ios(options)
  return unless options.platform == :ios

  {
    'address' => options.address,
    'module' => options.modulename,
    'arch' => options.arch
  }.each { |arg, check| raise(OptionParser::MissingArgument, arg) unless check }
end

.parse(args, io = $stdout) ⇒ Object

Return a structure describing the options.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tracetool/utils/cli.rb', line 14

def self.parse(args, io = $stdout)
  # The options specified on the command line will be collected in *options*.
  # We set default values here.
  opt_parser = ParseArgs.new(OpenStruct.new(sym_dir: Dir.pwd), io)
  options = opt_parser.parse(args)
  check(options)
  check_ios(options)
  options
rescue OptionParser::MissingArgument => e
  io.write ["Error occurred: #{e.message}", '', opt_parser.help].join("\n")
  io.write "\n"
  raise(e)
end

Instance Method Details

#helpObject



55
56
57
# File 'lib/tracetool/utils/cli.rb', line 55

def help
  @opt_parser.help
end

#parse(args) ⇒ Object



50
51
52
53
# File 'lib/tracetool/utils/cli.rb', line 50

def parse(args)
  @opt_parser.parse!(args)
  @options
end