Module: Capistrano::CLI::Help
- Included in:
- Capistrano::CLI
- Defined in:
- lib/capistrano/cli/help.rb
Constant Summary collapse
- LINE_PADDING =
7
- MIN_MAX_LEN =
30
- HEADER_LEN =
60
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #execute_requested_actions_with_help(config) ⇒ Object
-
#explain_task(config, name) ⇒ Object
:nodoc:.
-
#format_text(text) ⇒ Object
:nodoc:.
-
#long_help ⇒ Object
:nodoc:.
-
#output_columns ⇒ Object
:nodoc:.
-
#task_list(config, pattern = true) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
8 9 10 11 |
# File 'lib/capistrano/cli/help.rb', line 8 def self.included(base) #:nodoc: base.send :alias_method, :execute_requested_actions_without_help, :execute_requested_actions base.send :alias_method, :execute_requested_actions, :execute_requested_actions_with_help end |
Instance Method Details
#execute_requested_actions_with_help(config) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/capistrano/cli/help.rb', line 13 def execute_requested_actions_with_help(config) if [:tasks] task_list(config, [:tasks]) elsif [:explain] explain_task(config, [:explain]) else execute_requested_actions_without_help(config) end end |
#explain_task(config, name) ⇒ Object
:nodoc:
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/capistrano/cli/help.rb', line 71 def explain_task(config, name) #:nodoc: task = config.find_task(name) if task.nil? warn "The task `#{name}' does not exist." else puts "-" * HEADER_LEN puts "cap #{name}" puts "-" * HEADER_LEN if task.description.empty? puts "There is no description for this task." else puts format_text(task.description) end puts end end |
#format_text(text) ⇒ Object
:nodoc:
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/capistrano/cli/help.rb', line 96 def format_text(text) #:nodoc: formatted = "" text.each_line do |line| indentation = line[/^\s+/] || "" indentation_size = indentation.split(//).inject(0) { |c,s| c + (s[0] == ?\t ? 8 : 1) } line_length = output_columns - indentation_size line_length = MIN_MAX_LEN if line_length < MIN_MAX_LEN lines = line.strip.gsub(/(.{1,#{line_length}})(?:\s+|\Z)/, "\\1\n").split(/\n/) if lines.empty? formatted << "\n" else formatted << lines.map { |l| "#{indentation}#{l}\n" }.join end end formatted end |
#long_help ⇒ Object
:nodoc:
90 91 92 93 94 |
# File 'lib/capistrano/cli/help.rb', line 90 def long_help #:nodoc: help_text = File.read(File.join(File.dirname(__FILE__), "help.txt")) self.class.ui.page_at = self.class.ui.output_rows - 2 self.class.ui.say format_text(help_text) end |
#output_columns ⇒ Object
:nodoc:
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/capistrano/cli/help.rb', line 113 def output_columns #:nodoc: if ( @output_columns.nil? ) if ( self.class.ui.output_cols.nil? ) @output_columns = 80 else @output_columns = self.class.ui.output_cols end end @output_columns end |
#task_list(config, pattern = true) ⇒ Object
:nodoc:
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 |
# File 'lib/capistrano/cli/help.rb', line 23 def task_list(config, pattern = true) #:nodoc: tool_output = [:tool] if pattern.is_a?(String) tasks = config.task_list(:all).select {|t| t.fully_qualified_name =~ /#{pattern}/} end if tasks.nil? || tasks.length == 0 warn "Pattern '#{pattern}' not found. Listing all tasks.\n\n" if !tool_output && !pattern.is_a?(TrueClass) tasks = config.task_list(:all) end if tasks.empty? warn "There are no tasks available. Please specify a recipe file to load." unless tool_output else all_tasks_length = tasks.length if [:verbose].to_i < 1 tasks = tasks.reject { |t| t.description.empty? || t.description =~ /^\[internal\]/ } end tasks = tasks.sort_by { |task| task.fully_qualified_name } longest = tasks.map { |task| task.fully_qualified_name.length }.max max_length = output_columns - longest - LINE_PADDING max_length = MIN_MAX_LEN if max_length < MIN_MAX_LEN tasks.each do |task| if tool_output puts "cap #{task.fully_qualified_name}" else puts "cap %-#{longest}s # %s" % [task.fully_qualified_name, task.brief_description(max_length)] end end unless tool_output if all_tasks_length > tasks.length puts puts "Some tasks were not listed, either because they have no description," puts "or because they are only used internally by other tasks. To see all" puts "tasks, type `#{File.basename($0)} -vT'." end puts puts "Extended help may be available for these tasks." puts "Type `#{File.basename($0)} -e taskname' to view it." end end end |