class Tracetool::ParseArgs
Tracetool
cli args parser
Constants
- ARCH_LIST
List of supported abis. Only needed for iOS unpacking
Public Class Methods
check(options)
click to toggle source
# 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)
click to toggle source
# 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
new(defaults, io)
click to toggle source
# File lib/tracetool/utils/cli.rb, line 44 def initialize(defaults, io) @io = io @options = defaults @opt_parser = gen_opt_parser end
parse(args, io = $stdout)
click to toggle source
Return a structure describing the options.
# 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
Public Instance Methods
help()
click to toggle source
# File lib/tracetool/utils/cli.rb, line 55 def help @opt_parser.help end
parse(args)
click to toggle source
# File lib/tracetool/utils/cli.rb, line 50 def parse(args) @opt_parser.parse!(args) @options end
Private Instance Methods
gen_opt_parser()
click to toggle source
# File lib/tracetool/utils/cli.rb, line 61 def gen_opt_parser OptionParser.new do |opts| opt_banner(opts) opts.separator '' opt_common(opts) opts.separator '' opt_ios(opts) opts.separator '' opt_default(opts) end end
opt_common(opts)
click to toggle source
# File lib/tracetool/utils/cli.rb, line 81 def opt_common(opts) opts.separator 'Common options:' # Specify arch opts.on('--arch ARCH', ARCH_LIST, "Specify arch #{ARCH_LIST.join(', ')}") do |arch| @options.arch = arch end # Specify platform opts.on('--platform PLATORM', %i[android ios], 'Specify platform (android, ios)') do |platform| @options.platform = platform end # Symbols dir opts.on('--symbols [SYMBOLS]', 'Symbols dir. Using current working dir if not specified') do |dir| @options.sym_dir = dir end end
opt_default(opts)
click to toggle source
# File lib/tracetool/utils/cli.rb, line 112 def opt_default(opts) opts.separator 'Base options:' # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail('-h', '--help', 'Show this message') do @io.write opts @io.write "\n" exit end # Another typical switch to print the version. opts.on_tail('--version', 'Show version') do @io.write 'tracetool ' + Tracetool::Version.to_s exit end end
opt_ios(opts)
click to toggle source
# File lib/tracetool/utils/cli.rb, line 99 def opt_ios(opts) opts.separator 'IOS specific options' # Addres opts.on('--address ADDRESS', 'Baseline address for ios builds') do |address| @options.address = address end # Modulename -- execution entry point opts.on('--module MODULENAME', 'Entry point for ios builds') do |modulename| @options.modulename = modulename end end