lib/ruboto/commands/base.rb in ruboto-0.11.0 vs lib/ruboto/commands/base.rb in ruboto-0.12.0.rc.0
- old
+ new
@@ -6,11 +6,10 @@
require 'ruboto/util/asset_copier'
require 'ruboto/util/log_action'
require 'ruboto/util/xml_element'
require 'ruboto/util/code_formatting'
require 'ruboto/util/build'
-require 'ruboto/util/update'
require 'ruboto/util/verify'
require 'ruboto/util/scan_in_api'
require 'ruboto/core_ext/array'
require 'ruboto/core_ext/object'
@@ -18,39 +17,41 @@
module Commands
module Base
include Ruboto::SdkVersions
def self.main
- Main {
+ Main do
mode 'gen' do
+ require 'ruboto/util/update'
+
mode 'app' do
include Ruboto::Util::LogAction
include Ruboto::Util::Build
include Ruboto::Util::Update
include Ruboto::Util::Verify
- option('package'){
+ option('package') {
required
argument :required
description 'Name of package. Must be unique for every app. A common pattern is yourtld.yourdomain.appname (Ex. org.ruboto.irb)'
}
- option('name'){
+ option('name') {
argument :required
description 'Name of your app. Defaults to the last part of the package name capitalized.'
}
- option('activity'){
+ option('activity') {
argument :required
description 'Name of your primary Activity. Defaults to the name of the application with Activity appended.'
}
- option('path'){
+ option('path') {
argument :required
description 'Path to where you want your app. Defaults to the last part of the package name.'
}
option('target') {
argument :required
defaults DEFAULT_TARGET_SDK
- description "Android version to target. Must begin with 'android-' (e.g., 'android-8' for froyo)"
+ description "Android version to target. Must begin with 'android-' (e.g., 'android-10' for gingerbread)"
}
option('min-sdk') {
argument :required
description "Minimum android version supported. Must begin with 'android-'."
}
@@ -63,11 +64,11 @@
cast :boolean
}
def run
package = params['package'].value
- name = params['name'].value || package.split('.').last.split('_').map{|s| s.capitalize}.join
+ name = params['name'].value || package.split('.').last.split('_').map { |s| s.capitalize }.join
name[0..0] = name[0..0].upcase
activity = params['activity'].value || "#{name}Activity"
path = params['path'].value || package.split('.').last
target = params['target'].value
min_sdk = params['min-sdk'].value || target
@@ -89,12 +90,12 @@
Dir.chdir path do
FileUtils.rm_f "src/#{package.gsub '.', '/'}/#{activity}.java"
puts "Removed file #{"src/#{package.gsub '.', '/'}/#{activity}"}.java"
FileUtils.rm_f 'res/layout/main.xml'
puts 'Removed file res/layout/main.xml'
- verify_strings.root.elements['string'].text = name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2')
- File.open('res/values/strings.xml', 'w') {|f| verify_strings.document.write(f, 4)}
+ verify_strings.root.elements['string'].text = name.gsub(/([A-Z]+)([A-Z][a-z])/, '\1 \2').gsub(/([a-z\d])([A-Z])/, '\1 \2')
+ File.open('res/values/strings.xml', 'w') { |f| verify_strings.document.write(f, 4) }
end
puts 'Done'
Dir.chdir root do
update_manifest min_sdk[/\d+/], target[/\d+/], true
@@ -129,23 +130,23 @@
mode 'class' do
include Ruboto::Util::Build
include Ruboto::Util::Verify
- argument('class'){
+ argument('class') {
required
- alternatives = Dir[File.join(Ruboto::ASSETS, 'src/Inheriting*.java')].map{|f| File.basename(f)[10..-6]} - %w(Class)
- description "the Android Class that you want: #{alternatives[0..-2].map{|c| "#{c}, "}}or #{alternatives[-1]}"
- validate {|v| alternatives.include? v}
+ alternatives = Dir[File.join(Ruboto::ASSETS, 'src/Inheriting*.java')].map { |f| File.basename(f)[10..-6] } - %w(Class)
+ description "the Android Class that you want: #{alternatives[0..-2].map { |c| "#{c}, " }}or #{alternatives[-1]}"
+ validate { |v| alternatives.include? v }
}
- option('script_name'){
+ option('script_name') {
argument :required
description 'name of the ruby script that this class will execute. Should end in .rb. Optional.'
}
- option('name'){
+ option('name') {
required
argument :required
description 'name of the class (and file). Should be CamelCase'
}
@@ -172,159 +173,159 @@
end
mode 'subclass' do
include Ruboto::Util::Build
- argument('class'){
+ argument('class') {
required
description 'the Android Class that you want to subclass (e.g., package.Class).'
}
- option('name'){
+ option('name') {
required
argument :required
description 'name of the class (and file). Should be CamelCase'
}
- option('package'){
+ option('package') {
argument :required
description 'package for the new class (if not specified, uses project package)'
}
- option('method_base'){
+ option('method_base') {
required
- validate {|i| %w(all on none abstract).include?(i)}
+ validate { |i| %w(all on none abstract).include?(i) }
argument :required
description 'the base set of methods to generate (adjusted with method_include and method_exclude): all, none, abstract, on (e.g., onClick)'
}
- option('method_include'){
+ option('method_include') {
argument :required
defaults ''
description 'additional methods to add to the base list'
}
- option('method_exclude'){
+ option('method_exclude') {
argument :required
defaults ''
description 'methods to remove from the base list'
}
- option('implements'){
+ option('implements') {
required
argument :required
defaults ''
description 'comma separated list interfaces to implement'
}
- option('force'){
+ option('force') {
argument :required
- validate {|i| %w(include exclude).include?(i)}
+ validate { |i| %w(include exclude).include?(i) }
description "force handling of added and deprecated methods (values: 'include' or 'exclude') unless individually included or excluded"
}
def run
generate_inheriting_file 'Class', params['name'].value
generate_subclass_or_interface(
- %w(class name package method_base method_include method_exclude implements force).inject({}) {|h, i| h[i.to_sym] = params[i].value; h})
+ %w(class name package method_base method_include method_exclude implements force).inject({}) { |h, i| h[i.to_sym] = params[i].value; h })
end
end
mode 'interface' do
include Ruboto::Util::Build
- argument('interface'){
+ argument('interface') {
required
description 'the Android Interface that you want to implement (e.g., package.Interface).'
}
- option('name'){
+ option('name') {
required
argument :required
description 'name of the class (and file) that will implement the interface. Should be CamelCase'
}
- option('package'){
+ option('package') {
argument :required
description 'package for the new class (if not specified, uses project package)'
}
- option('force'){
+ option('force') {
argument :required
- validate {|i| %w(include exclude).include?(i)}
+ validate { |i| %w(include exclude).include?(i) }
description "force added and deprecated interfaces (values: 'include' or 'exclude')"
}
def run
# FIXME(uwe): DEPRECATED! Remove before Ruboto version 1.0.0.
puts "\nThe use of \"ruboto gen interface\" has been deprecated. Please use\n\n ruboto gen subclass\n\ninstead.\n\n"
generate_inheriting_file 'Class', params['name'].value
- generate_subclass_or_interface %w(interface name package force).inject({}) {|h, i| h[i.to_sym] = params[i].value; h}
+ generate_subclass_or_interface %w(interface name package force).inject({}) { |h, i| h[i.to_sym] = params[i].value; h }
end
end
mode 'core' do
include Ruboto::Util::Build
- argument('class'){
+ argument('class') {
required
- validate {|i| %w(Activity Service BroadcastReceiver View PreferenceActivity TabActivity OnClickListener OnItemClickListener OnItemSelectedListener all).include?(i)}
+ validate { |i| %w(Activity Service BroadcastReceiver View PreferenceActivity TabActivity OnClickListener OnItemClickListener OnItemSelectedListener all).include?(i) }
description "Activity, Service, BroadcastReceiver, View, OnClickListener, OnItemClickListener, OnItemSelectedListener, or all (default = all); Other activities not included in 'all': PreferenceActivity, TabActivity"
}
- option('method_base'){
+ option('method_base') {
required
argument :required
- validate {|i| %w(all on none).include?(i)}
+ validate { |i| %w(all on none).include?(i) }
defaults 'on'
description 'the base set of methods to generate (adjusted with method_include and method_exclude): all, none, on (e.g., onClick)'
}
- option('method_include'){
+ option('method_include') {
required
argument :required
defaults ''
description 'additional methods to add to the base list'
}
- option('method_exclude'){
+ option('method_exclude') {
required
argument :required
defaults ''
description 'methods to remove from the base list'
}
- option('implements'){
+ option('implements') {
required
argument :required
defaults ''
description "for classes only, interfaces to implement (cannot be used with 'gen core all')"
}
- option('force'){
+ option('force') {
argument :required
- validate {|i| %w(include exclude).include?(i)}
+ validate { |i| %w(include exclude).include?(i) }
description "force handling of added and deprecated methods (values: 'include' or 'exclude') unless individually included or excluded"
}
def run
- abort("specify 'implements' only for Activity, Service, BroadcastReceiver, PreferenceActivity, or TabActivity") unless
- %w(Activity Service BroadcastReceiver PreferenceActivity TabActivity).include?(params['class'].value) or params['implements'].value == ''
- generate_core_classes [:class, :method_base, :method_include, :method_exclude, :implements, :force].inject({}) {|h, i| h[i] = params[i.to_s].value; h}
+ abort("specify 'implements' only for Activity, Service, BroadcastReceiver, PreferenceActivity, or TabActivity") unless %w(Activity Service BroadcastReceiver PreferenceActivity TabActivity).include?(params['class'].value) or params['implements'].value == ''
+ generate_core_classes [:class, :method_base, :method_include, :method_exclude, :implements, :force].inject({}) { |h, i| h[i] = params[i.to_s].value; h }
end
end
end
mode 'update' do
+ require 'ruboto/util/update'
include Ruboto::Util::LogAction
include Ruboto::Util::Update
include Ruboto::Util::Verify
argument('what') {
required
# FIXME(uwe): Deprecated "ruboto update ruboto" in Ruboto 0.8.1. Remove september 2013.
- validate {|i| %w(jruby app ruboto).include?(i)}
+ validate { |i| %w(jruby app ruboto).include?(i) }
description "What do you want to update: 'app', 'jruby', or 'ruboto'"
}
option('force') {
description "force an update even if the version hasn't changed"
@@ -355,18 +356,27 @@
update_icons force
update_core_classes 'include'
update_bundle
when 'jruby' then
update_jruby(params['force'].value, true) || abort
- # FIXME(uwe): Deprecated in Ruboto 0.8.1. Remove september 2013.
+ # FIXME(uwe): Deprecated in Ruboto 0.8.1. Remove september 2013.
when 'ruboto' then
puts "\nThe 'ruboto update ruboto' command has been deprecated. Use\n\n ruboto update app\n\ninstead.\n\n"
update_ruboto(params['force'].value) || abort
end
end
end
+ mode 'setup' do
+ require 'ruboto/util/setup'
+ include Ruboto::Util::Setup
+
+ def run
+ setup_ruboto
+ end
+ end
+
option 'version' do
description 'display ruboto version'
end
# just running `ruboto`
@@ -389,10 +399,10 @@
Execute `ruboto gen app --help` for instructions on how to generate a fresh Ruby-enabled Android app
Execute `ruboto --help` for other options
}
end
end
- }
+ end
end
end
end
end