Class: Apu::MainApp
- Inherits:
-
Object
- Object
- Apu::MainApp
- Defined in:
- lib/apu.rb
Instance Method Summary collapse
- #android_home_is_defined ⇒ Object
- #call ⇒ Object
- #create_options_parser(args) ⇒ Object
-
#initialize(arguments) ⇒ MainApp
constructor
A new instance of MainApp.
-
#manage_opts ⇒ Object
Manage options.
Constructor Details
#initialize(arguments) ⇒ MainApp
Returns a new instance of MainApp.
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/apu.rb', line 10 def initialize(arguments) # defaults @app_path = Dir.pwd @package_flag = false @uninstall_flag = false @install_flag = false @android_home_flag = false @launcher_flag = false @run_flag = false @clear_flag = false @android_studio_flag = false @require_analyses = true # if !!arguments # arguments.push '-h' # end # Parse Options (arguments) manage_opts end |
Instance Method Details
#android_home_is_defined ⇒ Object
149 150 151 152 |
# File 'lib/apu.rb', line 149 def android_home_is_defined sdk = `echo $ANDROID_HOME`.gsub("\n",'') !sdk.empty? end |
#call ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/apu.rb', line 154 def call unless android_home_is_defined puts "\nWARNING: your #{'$ANDROID_HOME'.yellow} is not defined\n" puts "\nhint: in your #{'~/.bashrc'.yellow} add:\n #{"export ANDROID_HOME=\"/Users/cesarferreira/Library/Android/sdk/\"".yellow}" puts "\nNow type #{'source ~/.bashrc'.yellow}\n\n" exit 1 end end |
#create_options_parser(args) ⇒ Object
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/apu.rb', line 86 def (args) #@opt_parser = OptionParser.new do |opts| args. do |opts| opts. = "Usage: apu [OPTIONS]" opts.separator '' opts.separator "Options" opts.on('-p PATH', '--path PATH', 'Custom path to android project') do |app_path| @app_path = app_path if @app_path != '.' end opts.on('-k', '--package', 'Retrieves package name (eg. com.example.app)') do |value| @package_flag = true end opts.on('-u', '--uninstall', 'Uninstalls the apk from your device') do |app_path| @uninstall_flag = true end opts.on('-i', '--install', 'Installs the apk on your device') do |install| @install_flag = true end opts.on('-a', '--android-home', 'Checks if the ANDROID_HOME variable is defined') do |home| @android_home_flag = true @require_analyses = false end opts.on('-l', '--launcher', 'Get the launcher activity path') do |app_path| @launcher_flag = true end opts.on('-o', '--open', 'Open the build on the device') do |flavour| @run_flag = true end opts.on('-A', '--android-studio', 'Opens project on android studio') do |flavour| @android_studio_flag = true end opts.on('-c', '--clear', 'Clear app data') do |flavour| @clear_flag = true end opts.on('-r', '--release', 'Create release version and opens the folder') do |flavour| @clear_flag = true end opts.on('-h', '--help', 'Displays help') do @require_analyses = false puts opts.help exit end opts.on('-v', '--version', 'Displays version') do @require_analyses = false puts Apu::VERSION exit end opts.parse! end end |
#manage_opts ⇒ Object
Manage options
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/apu.rb', line 39 def manage_opts if @require_analyses # instatiate android project android_project = AndroidProject.new(@app_path) # is a valid android project? unless android_project.is_valid puts "#{@app_path.red} is not a valid android project" exit end end if @package_flag puts android_project.get_package_name.green end if @uninstall_flag android_project.uninstall_application end if @install_flag android_project.install end if @android_home_flag puts android_home_is_defined end if @launcher_flag puts android_project.get_launchable_activity.green end if @android_studio_flag system('open -a Android\ Studio ' + @app_path) end if @run_flag #android_project.install system(android_project.get_execute_line) end if @clear_flag android_project.clear_app_data end end |