./lib/cupertino/provisioning_portal/commands/profiles.rb in cupertino-0.8.0 vs ./lib/cupertino/provisioning_portal/commands/profiles.rb in cupertino-0.8.1

- old
+ new

@@ -28,10 +28,30 @@ end end alias_command :profiles, :'profiles:list' +command :'profiles:download' do |c| + c.syntax = 'ios profiles:download' + c.summary = 'Downloads the Provisioning Profiles' + c.description = '' + + c.action do |args, options| + type = args.first.downcase.to_sym rescue nil + profiles = try{agent.list_profiles(type ||= :development)} + profiles = profiles.find_all{|profile| profile.status == 'Active'} + + say_warning "No active #{type} profiles found." and abort if profiles.empty? + profile = choose "Select a profile to download:", *profiles + if filename = agent.download_profile(profile) + say_ok "Successfully downloaded: '#{filename}'" + else + say_error "Could not download profile" + end + end +end + command :'profiles:manage:devices' do |c| c.syntax = 'ios profiles:manage:devices' c.summary = 'Manage active devices for a development provisioning profile' c.description = '' @@ -64,26 +84,66 @@ say_ok "Successfully managed devices" end end -alias_command :'profiles:manage', :'profiles:manage:devices' +alias_command :'profiles:devices', :'profiles:manage:devices' -command :'profiles:download' do |c| - c.syntax = 'ios profiles:download' - c.summary = 'Downloads the Provisioning Profiles' +command :'profiles:manage:devices:add' do |c| + c.syntax = 'ios profiles:manage:devices:add PROFILE_NAME DEVICE_NAME=DEVICE_ID [...]' + c.summary = 'Add active devices to a Provisioning Profile' c.description = '' c.action do |args, options| - type = args.first.downcase.to_sym rescue nil - profiles = try{agent.list_profiles(type ||= :development)} - profiles = profiles.find_all{|profile| profile.status == 'Active'} + profiles = try{agent.list_profiles(:development) + agent.list_profiles(:distribution)} + profile = profiles.find {|profile| profile.name == args.first } - say_warning "No active #{type} profiles found." and abort if profiles.empty? - profile = choose "Select a profile to download:", *profiles - if filename = agent.download_profile(profile) - say_ok "Successfully downloaded: '#{filename}'" - else - say_error "Could not download profile" + say_warning "No provisioning profiles named #{args.first} were found." and abort unless profile + + devices = [] + args[1..-1].each do |arg| + components = arg.strip.gsub(/\"/, '').split(/\=/) + device = Device.new + device.name = components.first + device.udid = components.last + devices << device end + + agent.manage_devices_for_profile(profile) do |on, off| + on + devices + end + + say_ok "Successfully added devices to #{args.first}." end end + +alias_command :'profiles:devices:add', :'profiles:manage:devices:add' + +command :'profiles:manage:devices:remove' do |c| + c.syntax = 'ios profiles:manage:devices:remove PROFILE_NAME DEVICE_NAME=DEVICE_ID [...]' + c.summary = 'Remove active devices from a Provisioning Profile.' + c.description = '' + + c.action do |args, options| + profiles = try{agent.list_profiles(:development) + agent.list_profiles(:distribution)} + profile = profiles.find {|profile| profile.name == args.first } + + say_warning "No provisioning profiles named #{args.first} were found." and abort unless profile + + devices = [] + args[1..-1].each do |arg| + components = arg.strip.gsub(/\"/, '').split(/\=/) + device = Device.new + device.name = components.first + device.udid = components.last + devices << device + end + + agent.manage_devices_for_profile(profile) do |on, off| + on.delete_if {|active| devices.any? {|inactive| inactive.udid == active.udid }} + end + + say_ok "Successfully removed devices from #{args.first}." + end +end + +alias_command :'profiles:devices:remove', :'profiles:manage:devices:remove'