Class: DryRun::MainApp
- Inherits:
-
Object
- Object
- DryRun::MainApp
- Defined in:
- lib/dryrun.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.
- #outdated_verification ⇒ Object
- #pick_device ⇒ Object
Constructor Details
#initialize(arguments) ⇒ MainApp
Returns a new instance of MainApp.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dryrun.rb', line 14 def initialize(arguments) outdated_verification @url = ['-h', '--help', '-v', '--version'].include?(arguments.first) ? nil : arguments.shift # defaults @app_path = nil @custom_module = nil @flavour = '' @tag = nil @branch = "master" # Parse Options arguments.push "-h" unless @url (arguments) end |
Instance Method Details
#android_home_is_defined ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/dryrun.rb', line 130 def android_home_is_defined if !Gem.win_platform? sdk = `echo $ANDROID_HOME`.gsub("\n",'') else sdk = `echo %ANDROID_HOME%`.gsub("\n",'') end !sdk.empty? end |
#call ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/dryrun.rb', line 139 def call unless android_home_is_defined puts "\nWARNING: your #{'$ANDROID_HOME'.yellow} is not defined\n" puts "\nhint: in your #{'~/.bashrc'.yellow} or #{'~/.bash_profile'.yellow} add:\n #{"export ANDROID_HOME=\"/Users/cesarferreira/Library/Android/sdk/\"".yellow}" puts "\nNow type #{'source ~/.bashrc'.yellow}\n\n" exit 1 end @url = @url.split("?").first pick_device() github = Github.new(@url) unless github.is_valid puts "#{@url.red} is not a valid git @url" exit 1 end # clone the repository repository_path = github.clone(@branch, @tag) android_project = AndroidProject.new(repository_path, @app_path, @custom_module, @flavour, @device) # is a valid android project? unless android_project.is_valid puts "#{@url.red} is not a valid android project" exit 1 end puts "Using custom app folder: #{@app_path.green}" if @app_path puts "Using custom module: #{@custom_module.green}" if @custom_module # clean and install the apk android_project.install puts "\n> If you want to remove the app you just installed, execute:\n#{android_project.get_uninstall_command.yellow}\n\n" end |
#create_options_parser(args) ⇒ Object
30 31 32 33 34 35 36 37 38 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 |
# File 'lib/dryrun.rb', line 30 def (args) args. do |opts| opts. = "Usage: dryrun GIT_URL [OPTIONS]" opts.separator '' opts.separator "Options" opts.on('-m MODULE_NAME', '--module MODULE_NAME', 'Custom module to run') do |custom_module| @custom_module = custom_module end opts.on('-b BRANCH_NAME', '--branch BRANCH_NAME', 'Checkout custom branch to run') do |branch| @branch = branch end opts.on('-f', '--flavour FLAVOUR', 'Custom flavour (e.g. dev, qa, prod)') do |flavour| @flavour = flavour.capitalize end opts.on('-p PATH', '--path PATH', 'Custom path to android project') do |app_path| @app_path = app_path end opts.on('-t TAG', '--tag TAG', 'Checkout tag/commit hash to clone (e.g. "v0.4.5", "6f7dd4b")') do |tag| @tag = tag end opts.on('-h', '--help', 'Displays help') do puts opts.help exit end opts.on('-v', '--version', 'Displays the version') do puts DryRun::VERSION exit end opts.parse! end end |
#outdated_verification ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dryrun.rb', line 71 def outdated_verification is_up_to_date = DryrunUtils.is_up_to_date if is_up_to_date return end input = nil begin input = ask "\n#{'Your Dryrun version is outdated, want to update?'.yellow} #{'[Y/n]:'.white}" end while !['y', 'n', 's'].include?(input.downcase) if input.downcase.eql? 'y' DryrunUtils.execute('gem update dryrun') end end |
#pick_device ⇒ Object
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/dryrun.rb', line 91 def pick_device() if !Gem.win_platform? sdk = `echo $ANDROID_HOME`.gsub("\n",'') sdk = sdk + "/platform-tools/adb"; else sdk = `echo %ANDROID_HOME%`.gsub("\n",'') sdk = sdk + "/platform-tools/adb.exe" end puts "Searching for devices...".yellow adb = AdbSdkLib::Adb.new(sdk) devices = adb.devices; if devices.empty? puts "No devices attached, but I'll run anyway" end @device = nil if devices.size >= 2 puts "Pick your device (1,2,3...):" devices.each_with_index.map {|key, index| puts "#{index.to_s.green} - #{key} \n"} a = gets.chomp if a.match(/^\d+$/) && a.to_i <= (devices.length - 1) && a.to_i >= 0 @device = devices.to_a.at((a.to_i))[1] else @device = devices.first end else @device = devices.first end puts "Picked #{@device.to_s.green}" if @device end |