|
1 | 1 | #!/usr/bin/env ruby |
2 | 2 |
|
3 | | -require File.join(File.dirname(__FILE__), "kraken-mobile-helpers") |
4 | | -require File.join(File.dirname(__FILE__), "kraken-mobile-setup") |
5 | | -require File.join(File.dirname(__FILE__), "kraken-mobile-calabash-android") |
6 | | -$LOAD_PATH << File.expand_path("../../lib", __FILE__) |
7 | | -require 'kraken-mobile' |
| 3 | +require File.join(File.dirname(__FILE__), 'kraken_mobile_helpers') |
| 4 | +require File.join(File.dirname(__FILE__), 'kraken_mobile_setup') |
| 5 | +require File.join(File.dirname(__FILE__), 'kraken_mobile_calabash_android') |
| 6 | +$LOAD_PATH << File.expand_path('../lib', __dir__) |
| 7 | +require 'kraken_mobile' |
8 | 8 | require 'kraken-mobile/constants' |
9 | 9 |
|
10 | 10 | #------------------------------- |
11 | 11 | # AGV reader helper |
12 | 12 | #------------------------------- |
13 | 13 |
|
14 | | -def read_specified_runner |
15 | | - runner_command = ARGV.select { |arg| arg.include?("--runner=") }.first |
16 | | - if runner_command |
17 | | - formatted_runner_command = runner_command.strip.downcase |
18 | | - formatted_runner_command.slice!("--runner=") |
19 | | - formatted_runner_command |
20 | | - end |
21 | | -end |
| 14 | +def read_configuration |
| 15 | + configuration_command = ARGV.select do |arg| |
| 16 | + arg.include?('--configuration=') |
| 17 | + end.first |
| 18 | + return if configuration_command.nil? |
22 | 19 |
|
23 | | -def read_specified_protocol |
24 | | - protocol_command = ARGV.select { |arg| arg.include?("--protocol=") }.first |
25 | | - if protocol_command |
26 | | - formatted_protocol_command = protocol_command.strip.downcase |
27 | | - formatted_protocol_command.slice!("--protocol=") |
28 | | - if KrakenMobile::Constants::SUPPORTED_PROTOCOLS.include?(formatted_protocol_command) |
29 | | - formatted_protocol_command |
30 | | - else # Protocol not supported. |
31 | | - raise "Specified protocol not supported." |
32 | | - end |
33 | | - else # If protocol not specified use file based as default. |
34 | | - KrakenMobile::Constants::FILE_PROTOCOL |
35 | | - end |
| 20 | + configuration_command = configuration_command.strip.downcase |
| 21 | + configuration_command.slice!('--configuration=') |
| 22 | + configuration_command |
36 | 23 | end |
37 | 24 |
|
38 | | -def read_configuration |
39 | | - configuration_command = ARGV.select { |arg| arg.include?("--configuration=") }.first |
40 | | - if configuration_command |
41 | | - configuration_command = configuration_command.strip.downcase |
42 | | - configuration_command.slice!("--configuration=") |
43 | | - configuration_command |
44 | | - end |
| 25 | +def read_user_entered_properties_path |
| 26 | + properties_command = ARGV.select { |arg| arg.include?('--properties=') }.first |
| 27 | + return if properties_command.nil? |
| 28 | + |
| 29 | + properties_command = properties_command.strip.downcase |
| 30 | + properties_command.slice!('--properties=') |
| 31 | + properties_command |
45 | 32 | end |
46 | 33 |
|
47 | | -def read_properties |
48 | | - properties_command = ARGV.select { |arg| arg.include?("--properties=") }.first |
49 | | - if properties_command |
50 | | - properties_command = properties_command.strip.downcase |
51 | | - properties_command.slice!("--properties=") |
52 | | - properties_command |
53 | | - end |
| 34 | +#------------------------------- |
| 35 | +# Helpers |
| 36 | +#------------------------------- |
| 37 | + |
| 38 | +def user_entered_apk_path |
| 39 | + return nil if ARGV.first.nil? |
| 40 | + |
| 41 | + first_argument = ARGV.first |
| 42 | + return nil if first_argument.start_with?('--') # Is argument parameter not apk |
| 43 | + |
| 44 | + File.expand_path(first_argument) |
54 | 45 | end |
55 | 46 |
|
56 | 47 | #------------------------------- |
57 | 48 | # Command reader |
58 | 49 | #------------------------------- |
59 | 50 |
|
60 | | -if ARGV.length == 0 |
61 | | - print_usage |
| 51 | +if ARGV.length.zero? |
| 52 | + print_usage |
62 | 53 | else |
63 | 54 | cmd = ARGV.shift |
64 | 55 | case cmd |
65 | | - when 'version' |
66 | | - require 'kraken-mobile/version' |
67 | | - puts KrakenMobile::VERSION |
68 | | - when 'devices' |
69 | | - require 'kraken-mobile/helpers/devices_helper/manager' |
70 | | - print_devices |
71 | | - when 'setup' |
72 | | - kraken_setup |
73 | | - else |
74 | | - runner_command = read_specified_runner() |
75 | | - protocol = read_specified_protocol() |
76 | | - configuration = read_configuration() |
77 | | - properties = read_properties() |
78 | | - if runner_command |
79 | | - case runner_command |
80 | | - when KrakenMobile::Constants::CALABASH_ANDROID |
81 | | - require File.join(File.dirname(__FILE__), "kraken-mobile-calabash-android") |
82 | | - handle_calabash_android(cmd, protocol, configuration, properties) |
83 | | - else |
84 | | - raise "Specified runner not supported." |
85 | | - end |
86 | | - else # If runner not specified use calabash android as default. |
87 | | - require File.join(File.dirname(__FILE__), "kraken-mobile-calabash-android") |
88 | | - handle_calabash_android(cmd, protocol, configuration, properties) |
89 | | - end |
| 56 | + when 'version' |
| 57 | + require 'kraken-mobile/version' |
| 58 | + puts KrakenMobile::VERSION |
| 59 | + when 'devices' |
| 60 | + require 'kraken-mobile/helpers/devices_helper/manager' |
| 61 | + print_devices |
| 62 | + when 'setup' |
| 63 | + KrakenSetup.new.run |
| 64 | + when 'gen' |
| 65 | + scaffold_folder_structure |
| 66 | + when 'resign' |
| 67 | + require 'calabash-android/helpers' |
| 68 | + puts 'Resigning APK with Calabash-Android' |
| 69 | + ensure_apk_is_specified |
| 70 | + resign_apk(user_entered_apk_path) |
| 71 | + when 'run' |
| 72 | + require File.join(File.dirname(__FILE__), 'kraken_mobile_calabash_android') |
| 73 | + configuration = read_configuration |
| 74 | + user_entered_properties_path = read_user_entered_properties_path |
| 75 | + handle_calabash_android(configuration, user_entered_properties_path) |
| 76 | + else |
| 77 | + print_usage |
90 | 78 | end |
91 | 79 | end |
0 commit comments