#!/usr/bin/env ruby require 'gli' require 'io/console' begin # XXX: Remove this begin/rescue before distributing your app require 'iosdeveloper' rescue LoadError STDERR.puts "In development, you need to use `bundle exec bin/iosdeveloper` to run your app" STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path" STDERR.puts "Feel free to remove this message from bin/adt now" exit 64 end DEFAULT_CONFIG_FILE_LOCATION = Dir.pwd + "/iosdeveloper.rc.yml" include GLI::App program_desc 'iOS Developer Tools' version IOSDeveloper::VERSION desc 'Location of the configuration file' arg_name 'config_file' default_value DEFAULT_CONFIG_FILE_LOCATION flag [:c, 'config-file'] desc 'Creates the configuration file containing username, password and optionally team name' command :init do |c| c.desc 'Apple ID' c.arg_name 'username' c.flag [:u, :username] c.desc 'Password' c.arg_name 'password' c.flag [:p, :password] c.desc 'Team name' c.arg_name 'team_name' c.flag [:t, :team] c.action do |global_options, options, args| File.open(global_options[:c]||DEFAULT_CONFIG_FILE_LOCATION, 'w', 0600) do |file| YAML.dump({"username" => options[:username], "password" => options[:password], "team" => options[:team]}, file) end end end desc 'List add registered devices' command 'list-devices' do |c| c.action do |global_options, options, args| devices = portal(global_options).list_devices puts "" puts "Registered devices:" puts devices end end desc 'Registers a new device' arg_name 'DEVICE_NAME DEVICE_ID' command 'add-device' do |c| c.action do |global_options, options, args| device_name = args.shift help_now!('device id is required') if device_name.nil? device_id = args.shift help_now!('device id is required') if device_id.nil? portal(global_options).add_device(device_name, device_id) end end desc 'Installs provisioning profile' arg_name 'PROFILE_NAME' command 'install-profile' do |c| c.switch [:a, 'all'] c.action do |global_options, options, args| portal = portal(global_options) if (options[:a]) portal.install_profile else profile_name = args.shift portal.install_profile(profile_name) end end end desc 'List provisioning profiles' command 'list-profiles' do |c| c.action do |global_options, options, args| profiles = portal(global_options).list_profiles puts "" profiles.each do |profile| puts "#{profile.name}|#{profile.app_id}|#{profile.status}" end end end def portal global_options config_file = YAML::load(File.read(global_options[:c]||DEFAULT_CONFIG_FILE_LOCATION)) username = config_file['username'] || raise("username not provided") password = config_file['password'] || raise("password not provided") team_name = config_file['team'] IOSDeveloper::ProvisioningPortal.new(username, password, team_name) end pre do |global, command, options, args| # Pre logic here # Return true to proceed; false to abort and not call the # chosen command # Use skips_pre before a command to skip this block # on that command only true end post do |global, command, options, args| # Post logic here # Use skips_post before a command to skip this # block on that command only end on_error do |exception| # Error logic here # return false to skip default error handling true end exit run(ARGV)