Class: ConsoleView
- Inherits:
-
Object
- Object
- ConsoleView
- Defined in:
- lib/console_view.rb
Constant Summary collapse
- FRAMEWORK_LIST_INDENTATION =
6
Instance Method Summary collapse
- #current_command_path ⇒ Object
-
#initialize(scaffolder) ⇒ ConsoleView
constructor
A new instance of ConsoleView.
- #read_user_input ⇒ Object
- #show(text) ⇒ Object
- #show_deprecated_command_argument_warning(command, deprecated_argument) ⇒ Object
- #show_detailed_help(command) ⇒ Object
- #show_extended_help ⇒ Object
- #show_help ⇒ Object
- #show_help_capture_single_run ⇒ Object
- #show_help_init_session ⇒ Object
- #show_help_setup ⇒ Object
- #show_help_start ⇒ Object
- #show_help_unknown(command) ⇒ Object
- #show_help_upload ⇒ Object
- #show_help_upload_no_open ⇒ Object
- #show_init_session_result(session_dir) ⇒ Object
- #show_internal_server_error(exception, log_file_name) ⇒ Object
- #show_kata_exit_message ⇒ Object
- #show_kata_upload_hint ⇒ Object
- #show_missing_command_argument_error(command, missing_argument) ⇒ Object
- #show_no_green_state_to_revert_to ⇒ Object
- #show_properties_file_missing_error(filename) ⇒ Object
- #show_revert_to_step(step) ⇒ Object
- #show_run_once_message(modified_file, modification_time) ⇒ Object
- #show_socket_error(command) ⇒ Object
- #show_start_kata(command, file, framework) ⇒ Object
- #show_unknown_framework_error(framework, templates) ⇒ Object
- #show_unknwon_command_message(command) ⇒ Object
- #show_upload_result(result) ⇒ Object
- #show_upload_start(session_directory, hostname, framework) ⇒ Object
- #show_usage ⇒ Object
Constructor Details
#initialize(scaffolder) ⇒ ConsoleView
Returns a new instance of ConsoleView.
9 10 11 12 |
# File 'lib/console_view.rb', line 9 def initialize scaffolder @scaffolder = scaffolder @template_machine = TextTemplateMachineFactory.create ShellWrapper.new end |
Instance Method Details
#current_command_path ⇒ Object
246 247 248 |
# File 'lib/console_view.rb', line 246 def current_command_path $0.gsub '/', '%/%' end |
#read_user_input ⇒ Object
242 243 244 |
# File 'lib/console_view.rb', line 242 def read_user_input STDIN.gets end |
#show(text) ⇒ Object
238 239 240 |
# File 'lib/console_view.rb', line 238 def show text puts @template_machine.render(text) end |
#show_deprecated_command_argument_warning(command, deprecated_argument) ⇒ Object
162 163 164 |
# File 'lib/console_view.rb', line 162 def show_deprecated_command_argument_warning command, deprecated_argument show "Argument #{deprecated_argument} is deprecated for command #{command}. Please remove it." end |
#show_detailed_help(command) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/console_view.rb', line 50 def show_detailed_help command command = command.gsub('-', '_') begin eval "show_help_#{command}" rescue show_help_unknown command end end |
#show_extended_help ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/console_view.rb', line 39 def show_extended_help show <<-helptext Usage: #{current_command_path} command [options] Commands: help <command> See the details of the command. init-session Create a new session dir within the .codersdojo dir. capture-single-run <shell_command> <kata_file> Capture a single run. start <shell_command> <kata_file> Start the continuous test loop. helptext end |
#show_help ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/console_view.rb', line 14 def show_help show <<-helptext CodersDojo-Client, http://www.codersdojo.org, Copyright by it-agile GmbH (http://www.it-agile.de) CodersDojo-Client automatically runs your code kata, logs the progress and uploads the kata to codersdojo.org. helptext show_usage end |
#show_help_capture_single_run ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/console_view.rb', line 117 def show_help_capture_single_run show <<-helptext capture-single-run <shell_command> <kata_file> Execute <shell-command> once for <kata_file>. The <kata_file> has to include the whole source code of the kata. The run will be captured into the newest session dir in the .codersdojo dir. Usually this command is used after a session dir has been created with the init-session command. helptext end |
#show_help_init_session ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/console_view.rb', line 108 def show_help_init_session show <<-helptext init-session Create a new session dir in the .codersdojo dir. Usually this command is used before using capture-single-run. helptext end |
#show_help_setup ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/console_view.rb', line 59 def show_help_setup templates = @scaffolder.list_templates_as_dotted_list FRAMEWORK_LIST_INDENTATION show <<-helptext setup <framework> <kata_file> Setup the environment for the kata for the given framework and kata file. The <kata_file> is the one file that will contain the source code of the code kata. If <kata_file> does not have an extension it will be added automatically - except if <framework> is ??? (see below). By now <framework> is one of these: #{templates} Use ??? as framework if your framework isn't in the list. Example: :%/%dojo%/%my_kata$ #{current_command_path} setup ruby.test-unit prime Setup the the environment for executing a code kata in kata file 'prime' with Ruby and test/unit. helptext end |
#show_help_start ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/console_view.rb', line 78 def show_help_start show <<-helptext start <shell_command> <kata_file> Start the continuous test runner, that runs <shell_command> whenever <kata_file> changes. The <kata_file> has to include the whole source code of the kata. Whenever the test runner is started, it creates a new session directory in the directory .codersdojo where it logs the steps of the kata. helptext end |
#show_help_unknown(command) ⇒ Object
146 147 148 149 150 |
# File 'lib/console_view.rb', line 146 def show_help_unknown command show <<-helptext Command #{command} not known. Try '#{current_command_path} help' to list the supported commands. helptext end |
#show_help_upload ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/console_view.rb', line 89 def show_help_upload show <<-helptext upload Upload the newest kata session in .codersdojo to codersdojo.com. After the kata is uploaded the browser is started with the URL of the uploaded kata. upload <session_directory> Upload the kata <session_directory> to codersdojo.com. <session_directory> is relative to the working directory. Examples: :%/%dojo%/%my_kata$ #{current_command_path} upload Upload the newest kata located in directory ".codersdojo" to codersdojo.com. :%/%dojo%/%my_kata$ #{current_command_path} upload .codersdojo%/%2010-11-02_16-21-53 Upload the kata located in directory ".codersdojo%/%2010-11-02_16-21-53" to codersdojo.com. helptext end |
#show_help_upload_no_open ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/console_view.rb', line 128 def show_help_upload_no_open show <<-helptext upload-no-open Upload the newest kata session in .codersdojo to codersdojo.com. upload-no-opem <session_directory> Upload the kata <session_directory> to codersdojo.com. <session_directory> is relative to the working directory. Examples: :%/%dojo%/%my_kata$ #{current_command_path} upload-no-open Upload the newest kata located in directory ".codersdojo" to codersdojo.com. :%/%dojo%/%my_kata$ #{current_command_path} upload-no-open .codersdojo%/%2010-11-02_16-21-53 Upload the kata located in directory ".codersdojo%/%2010-11-02_16-21-53" to codersdojo.com. helptext end |
#show_init_session_result(session_dir) ⇒ Object
234 235 236 |
# File 'lib/console_view.rb', line 234 def show_init_session_result session_dir show "Session directory created: #{session_dir}" end |
#show_internal_server_error(exception, log_file_name) ⇒ Object
221 222 223 224 225 226 227 228 |
# File 'lib/console_view.rb', line 221 def show_internal_server_error exception, log_file_name show <<-msg !!! WTF? !!! An internal server error occurred. This probably means that we sucked and there is !!! a bug. An error log was written to #{log_file_name}. !!! Please help us to fix the bug and send us the log file via email: [email protected] msg end |
#show_kata_exit_message ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/console_view.rb', line 202 def show <<-msg You finished your kata. Choose your next action: g) Revert to last green state. u) Upload the kata to http://www.codersdojo.com. e) Exit without uploading. r) Resume the kata. msg end |
#show_kata_upload_hint ⇒ Object
230 231 232 |
# File 'lib/console_view.rb', line 230 def show_kata_upload_hint show "You finished your kata. You can upload it with 'codersdojo upload'." end |
#show_missing_command_argument_error(command, missing_argument) ⇒ Object
157 158 159 160 |
# File 'lib/console_view.rb', line 157 def show_missing_command_argument_error command, missing_argument show "Command <#{command}> recognized but argument <#{missing_argument}> was missing.\n" show_detailed_help command end |
#show_no_green_state_to_revert_to ⇒ Object
188 189 190 |
# File 'lib/console_view.rb', line 188 def show_no_green_state_to_revert_to show "Sorry, no previous green state to revert to." end |
#show_properties_file_missing_error(filename) ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/console_view.rb', line 213 def show_properties_file_missing_error filename show <<-msg Property file #{filename} is missing. Maybe you created the directory structure with an older version of CodersDojo? Recreate the directory structure with the current version with 'codersdojo setup ...'. msg end |
#show_revert_to_step(step) ⇒ Object
184 185 186 |
# File 'lib/console_view.rb', line 184 def show_revert_to_step step show "Revert to step #{step}." end |
#show_run_once_message(modified_file, modification_time) ⇒ Object
170 171 172 173 174 |
# File 'lib/console_view.rb', line 170 def modified_file, modification_time time = modification_time.strftime("%X") date = modification_time.strftime("%x") show "\nFile #{modified_file} was modified at #{time} on #{date}. Run tests." end |
#show_socket_error(command) ⇒ Object
192 193 194 |
# File 'lib/console_view.rb', line 192 def show_socket_error command show "Encountered network error while <#{command}>. Is http://www.codersdojo.com down?" end |
#show_start_kata(command, file, framework) ⇒ Object
166 167 168 |
# File 'lib/console_view.rb', line 166 def show_start_kata command, file, framework show "Starting CodersDojo-Client with command #{command} and kata file #{file} with framework #{framework}. Use Ctrl+C to finish the kata." end |
#show_unknown_framework_error(framework, templates) ⇒ Object
196 197 198 199 200 |
# File 'lib/console_view.rb', line 196 def show_unknown_framework_error framework, templates show "Unkown framework #{framework}. Possible frameworks:" show templates show "Use ??? as framework if your framework isn't in the list." end |
#show_unknwon_command_message(command) ⇒ Object
152 153 154 155 |
# File 'lib/console_view.rb', line 152 def command show "Command #{command} not known.\n\n" show_usage end |
#show_upload_result(result) ⇒ Object
180 181 182 |
# File 'lib/console_view.rb', line 180 def show_upload_result result show result end |
#show_upload_start(session_directory, hostname, framework) ⇒ Object
176 177 178 |
# File 'lib/console_view.rb', line 176 def show_upload_start session_directory, hostname, framework show "Start upload from #{session_directory} with framework #{framework} to #{hostname}" end |
#show_usage ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/console_view.rb', line 23 def show_usage show <<-helptext Usage: #{current_command_path} command [options] Commands: help, -h, --help Print this help text. help <command> See the details of the command. xhelp Print help text for advanced commands. setup <framework> <kata_file> Setup the environment for running the kata. upload-zip [<session_dir>] Upload session as a ZIP file (beta feature) upload [<session_dir>] Upload the kata to http://www.codersdojo.org and open the kata in a browser. upload-no-open [<session_dir>] Upload the kata to http://www.codersdojo.org Report bugs to <[email protected]> helptext end |