Class: IOSDevTools::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/ios_dev_tools/commands/tool.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.command_name_to_class(command_name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ios_dev_tools/commands/tool.rb', line 43

def self.command_name_to_class command_name

  class_name=command_name_to_class_name command_name

  # create class definition
  command_class=nil
  begin
    command_class=IOSDevTools.const_get(class_name)
  rescue NameError
    #puts "Can't access class #{class_name}"
  end
  return command_class
end

.command_name_to_class_name(command_name) ⇒ Object



57
58
59
60
61
62
# File 'lib/ios_dev_tools/commands/tool.rb', line 57

def self.command_name_to_class_name command_name

  result=command_name.split("_").map{|e| e[0]=e[0].chr.upcase; e;}.join
  result

end

.parse_options(args) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ios_dev_tools/commands/tool.rb', line 64

def self.parse_options(args)

  options = Hash.new
  OptionParser.new do |opts|

    opts.banner = "Usage:
ios_tool sign -i \"iPhone Distribution: Name\" -p path/to/profile -o output/ipa/file [options] inputIpa"

    opts.separator ""
    opts.separator "Options:"

    opts.on("-p", "--profile PATH_TO_PROFILE", "Path to profile") do |profile_location|
      options[:profile_location] = profile_location
    end

    opts.on("-b", "--bundle-id [BUNDLE_IDENTIFIER]", "Bundle identifier") do |bundle_id|
      options[:bundle_id] = bundle_id
    end

    opts.on("-o", "--output OUTPUT_IPA_FILE", "Output ipa archive") do |output_ipa|
      options[:output_ipa] = output_ipa
    end

    opts.on("-i", "--identity IDENTITY", "Identity") do |identity|
      options[:identity] = identity
    end

    opts.on("-t", "--temp [TEMP_FOLDER]", "Temporary folder location") do |temp_folder|
      options[:temp_folder] = temp_folder
    end

    opts.separator ""
    opts.separator "Common options:"

    opts.on("-v", "--verbose", "Run verbosely") do |v|
      options[:verbose] = v
    end

    opts.on("--version", "Show version and exit") do |v|
      puts "Version: #{IOSDevTools::VERSION}"
      exit
    end

    # No argument, shows at tail.  This will print an options summary.
    # Try it and see!
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

  end.parse!(args)

  options[:input_file]=ARGV[0]
  mandatory=[options[:profile_location],options[:identity],options[:output_ipa],options[:input_file]]
  expected_number=mandatory.count
  real_number=mandatory.compact.count
  if expected_number != real_number
    # one of mandatory switches is missing
    # display help and exit
    parse_options ["-h"]
  end

  return options
end

.valid_command_name?(command_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/ios_dev_tools/commands/tool.rb', line 36

def self.valid_command_name? command_name

  valid_commands=["sign", "pack", "verify", "help"]
  return valid_commands.include? command_name

end

Instance Method Details

#process_cmd_line_args(cmd_line_arguments) ⇒ Object



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
# File 'lib/ios_dev_tools/commands/tool.rb', line 8

def process_cmd_line_args cmd_line_arguments

  command_name=cmd_line_arguments[0]

  if not command_name or command_name=="-h" or command_name=="--help"
    command_name="help"
  end

  if not Tool.valid_command_name? command_name
      puts "Unknown command"
      exit
  end

  # create class definition
  command_class=Tool.command_name_to_class command_name

  # NOTE:shift argument array to loose first element which is command name
  # the command is already recognised and is not needed any more
  # this simplifies options parsing inside commands
  ARGV.shift

  # use common factory method to create the command
  command=command_class.create_with_args ARGV
  # execute the command if created
  command.execute if command

end