Class: Pindo::Command::Android::Install

Inherits:
Pindo::Command::Android show all
Defined in:
lib/pindo/command/android/install.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

command_name, #initialize_options, run, use_cache?

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Install

Returns a new instance of Install.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pindo/command/android/install.rb', line 38

def initialize(argv)
    @args_apk_file = argv.shift_argument
    @options = initialize_options(argv)

    apk_option = @options[:apk] rescue nil
    if !apk_option.nil?
        @args_apk_file = apk_option
    end
    if @args_apk_file && !@args_apk_file.empty?
        @args_apk_file = @args_apk_file.strip.gsub(/\"/, '')
    end

    super(argv)
end

Class Method Details

.option_itemsObject



28
29
30
31
32
# File 'lib/pindo/command/android/install.rb', line 28

def self.option_items
  @option_items ||= Pindo::Options::OptionGroup.merge(
    Pindo::Options::ToolOptions.select(:apk)
  )
end

.optionsObject



34
35
36
# File 'lib/pindo/command/android/install.rb', line 34

def self.options
  option_items.map(&:to_claide_option).concat(super)
end

Instance Method Details

#runObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pindo/command/android/install.rb', line 57

def run
    # 1. 查找 adb
    @adb_path = find_adb
    puts "ADB: #{@adb_path}"

    # 2. 查找 APK 文件
    apk_file = find_apk_file
    puts "APK 文件: #{apk_file}"

    # 3. 检测可用设备
    devices = detect_available_devices
    if devices.empty?
        raise Informative, "未检测到可用的 Android 设备,请确认设备已连接并开启 USB 调试"
    end

    # 4. 选择设备
    device = select_device(devices)
    puts "目标设备: #{device[:brand]} #{device[:model]} (#{device[:serial]})"

    # 5. 安装 APK
    install_apk_to_device(apk_file, device)
end

#validate!Object



53
54
55
# File 'lib/pindo/command/android/install.rb', line 53

def validate!
    super
end