Class: Tracetool::ParseArgs
- Inherits:
-
Object
- Object
- Tracetool::ParseArgs
- 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
- .check(options) ⇒ Object
- .check_ios(options) ⇒ Object
-
.parse(args, io = $stdout) ⇒ Object
Return a structure describing the options.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(defaults, io) ⇒ ParseArgs
constructor
A new instance of ParseArgs.
- #parse(args) ⇒ Object
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() { 'platform' => .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() return unless .platform == :ios { 'address' => .address, 'module' => .modulename, 'arch' => .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) = opt_parser.parse(args) check() check_ios() rescue OptionParser::MissingArgument => e io.write ["Error occurred: #{e.}", '', opt_parser.help].join("\n") io.write "\n" raise(e) end |
Instance Method Details
#help ⇒ Object
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 |