Class: Apu::MainApp

Inherits:
Object
  • Object
show all
Defined in:
lib/apu.rb

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ MainApp

Returns a new instance of MainApp.



9
10
11
12
13
14
15
16
17
18
# File 'lib/apu.rb', line 9

def initialize(arguments)

  @app_path = `pwd`.tr("\n","")

  create_options_parser
  #@url = ['-h', '--help', '-v', '--version'].include?(arguments.first) ? nil : arguments.shift

  @opt_parser.parse!(arguments)

end

Instance Method Details

#android_home_is_definedObject



85
86
87
88
# File 'lib/apu.rb', line 85

def android_home_is_defined
  sdk = `echo $ANDROID_HOME`.gsub("\n",'')
  !sdk.empty?
end

#callObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/apu.rb', line 101

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_parserObject



20
21
22
23
24
25
26
27
28
29
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/apu.rb', line 20

def create_options_parser
  @opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: apu PATH [OPTIONS]"
    opts.separator  ''
    opts.separator  "Options"

    opts.on('-k', '--package', 'Retrieves package name (eg. com.example.app)') do |app_path|
      android_project = get_android_project_object
      puts android_project.get_package_name.green
      exit
    end

    opts.on('-u', '--uninstall', 'Uninstalls the apk from your device') do |app_path|
      android_project = get_android_project_object
      android_project.uninstall_application
      exit
    end

    opts.on('-i', '--install', 'Installs the apk on your device') do |app_path|
      android_project = get_android_project_object
      android_project.install
      exit
    end

    opts.on('-a', '--android-home', 'Checks if the ANDROID_HOME variable is defined') do |home|
      p android_home_is_defined
      exit
    end

    opts.on('-l', '--launcher', 'Get the launcher activity path') do |app_path|
      android_project = get_android_project_object
      puts android_project.get_launchable_activity.green
      exit
    end

    opts.on('-p PATH', '--path PATH', 'Custom path to android project') do |app_path|
      @app_path = app_path if @app_path != '.'
    end

    opts.on('-r', '--run', 'Run the build on the device') do |flavour|
      android_project = get_android_project_object

      android_project.install
      system(android_project.get_execute_line)
      exit
    end

    opts.on('-c', '--clear', 'Clear app data') do |flavour|
      android_project = get_android_project_object
      android_project.clear_app_data
    end

    opts.on('-h', '--help', 'Displays help') do
      puts opts.help
      exit
    end
    opts.on('-v', '--version', 'Displays version') do
      puts Apu::VERSION
      exit
    end


  end
end

#get_android_project_objectObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/apu.rb', line 90

def get_android_project_object
  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
  return android_project
end