Class: Gena::Application
- Inherits:
-
Thor
- Object
- Thor
- Gena::Application
- Defined in:
- lib/cli/cli.rb,
lib/cli/init.rb
Class Method Summary collapse
-
.class_for_command ⇒ Object
class_for_command - hash to store custom classes (actually Plugin subclasses) for each command registered with gena.
- .class_for_command=(commands) ⇒ Object
- .finish ⇒ Object
-
.help(shell, subcommand = false) ⇒ Object
Override help to forward.
- .plugin_classes ⇒ Object
-
.start(given_args = ARGV, config = {}) ⇒ Object
Override start to do custom dispatch (looking for plugin for unknown command).
Instance Method Summary collapse
Class Method Details
.class_for_command ⇒ Object
class_for_command - hash to store custom classes (actually Plugin subclasses) for each command registered with gena
11 12 13 |
# File 'lib/cli/cli.rb', line 11 def class_for_command @class_for_command ||= Hash.new end |
.class_for_command=(commands) ⇒ Object
15 16 17 |
# File 'lib/cli/cli.rb', line 15 def class_for_command=(commands) @class_for_command = commands end |
.finish ⇒ Object
91 92 93 94 |
# File 'lib/cli/cli.rb', line 91 def finish XcodeUtils.shared.save_project Application.new.check_gena_version end |
.help(shell, subcommand = false) ⇒ Object
Override help to forward
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 |
# File 'lib/cli/cli.rb', line 25 def help(shell, subcommand = false) #List plugin commands separately from Gena general commands plugins = [] class_for_command.each do |command, klass| plugins += klass.printable_commands(false) end plugins.uniq! list = printable_commands(true, subcommand) Thor::Util.thor_classes_in(self).each do |klass| list += klass.printable_commands(false) end list -= plugins # Remove this line to disable alphabetical sorting # list.sort! { |a, b| a[0] <=> b[0] } # Add this line to remove the help-command itself from the output # list.reject! {|l| l[0].split[1] == 'help'} if defined?(@package_name) && @package_name shell.say "#{@package_name} commands:" else shell.say "General commands:" end shell.print_table(list, :indent => 2, :truncate => true) shell.say (shell) shell.say "Plugins:" shell.print_table(plugins, :indent => 2, :truncate => true) end |
.plugin_classes ⇒ Object
19 20 21 |
# File 'lib/cli/cli.rb', line 19 def plugin_classes class_for_command.values.uniq end |
.start(given_args = ARGV, config = {}) ⇒ Object
Override start to do custom dispatch (looking for plugin for unknown command)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cli/cli.rb', line 65 def start(given_args = ARGV, config = {}) config[:shell] ||= Thor::Base.shell.new command_name = normalize_command_name(retrieve_command_name(given_args.dup)) clazz = command_name ? class_for_command[command_name] : nil if command_name && clazz clazz.dispatch(nil, given_args.dup, nil, config) else dispatch(nil, given_args.dup, nil, config) end finish rescue Thor::Error => e config[:debug] || ENV["THOR_DEBUG"] == "1" ? (raise e) : config[:shell].error(e.) exit(1) if exit_on_failure? rescue Errno::EPIPE # This happens if a thor command is piped to something like `head`, # which closes the pipe when it's done reading. This will also # mean that if the pipe is closed, further unnecessary # computation will not occur. exit(0) end |
Instance Method Details
#init ⇒ Object
7 8 9 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 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 |
# File 'lib/cli/init.rb', line 7 def init xcode_project_name = `find . -name *.xcodeproj` xcode_project_name.strip! xcode_project_name = ask_with_default("Enter path for #{set_color('project', Color::YELLOW)} or ENTER to continue (#{xcode_project_name}):", xcode_project_name) xcode_project = Xcodeproj::Project.open(xcode_project_name) main_target = nil test_target = nil xcode_project.native_targets.each do |target| if target.product_type == 'com.apple.product-type.application' main_target = target elsif target.product_type == 'com.apple.product-type.bundle.unit-test' test_target = target end end sources_path = common_path_in_target(main_target, 'main.m') tests_path = common_path_in_target(test_target, "#{sources_path}/") sources_path = relative_to_current_dir(sources_path) tests_path = relative_to_current_dir(tests_path) hash = Hash.new hash[:plugins_url] = [ 'https://github.com/alexgarbarev/gena-plugins.git' ] default_build_configuration = main_target.build_configuration_list.default_configuration_name || 'Debug' info_plist_value = main_target.build_configuration_list.get_setting('INFOPLIST_FILE')[default_build_configuration] if info_plist_value['$(SRCROOT)/'] info_plist_value['$(SRCROOT)/'] = '' end hash['company'] = xcode_project.root_object.attributes['ORGANIZATIONNAME'].to_s hash['prefix'] = xcode_project.root_object.attributes['CLASSPREFIX'].to_s hash['project_name'] = xcode_project.root_object.name hash['project_target'] = main_target.name hash['test_target'] = test_target.name hash['info_plist'] = info_plist_value hash['sources_dir'] = ask_with_default("Enter path for #{set_color('sources', Color::YELLOW)} or ENTER to continue (#{sources_path}):", sources_path) hash['tests_dir'] = ask_with_default("Enter path for #{set_color('tests', Color::YELLOW)} or ENTER to continue (#{tests_path}):", tests_path) say '===============================================================', Color::YELLOW print_table(hash) say '===============================================================', Color::YELLOW File.open('gena.plist', 'w') { |f| f.write hash.to_plist } say "'gena.plist' created..", Color::GREEN end |