Class: ConsoleView

Inherits:
Object
  • Object
show all
Defined in:
lib/console_view.rb

Constant Summary collapse

FRAMEWORK_LIST_INDENTATION =
6

Instance Method Summary collapse

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_pathObject



246
247
248
# File 'lib/console_view.rb', line 246

def current_command_path
  $0.gsub '/', '%/%'
end

#read_user_inputObject



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_helpObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/console_view.rb', line 39

def show_extended_help
show "Usage: \#{current_command_path} command [options]\nCommands:\nhelp <command>                                    See the details of the command.\ninit-session                                      Create a new session dir within the .codersdojo dir.\ncapture-single-run <shell_command> <kata_file>    Capture a single run.\nstart <shell_command> <kata_file>                 Start the continuous test loop.\n"
end

#show_helpObject



14
15
16
17
18
19
20
21
# File 'lib/console_view.rb', line 14

def show_help
  show "CodersDojo-Client, http://www.codersdojo.org, Copyright by it-agile GmbH (http://www.it-agile.de)\nCodersDojo-Client automatically runs your code kata, logs the progress and uploads the kata to codersdojo.org.\n\n"
  show_usage
end

#show_help_capture_single_runObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/console_view.rb', line 117

def show_help_capture_single_run
  show "  \ncapture-single-run <shell_command> <kata_file>  \n   Execute <shell-command> once for <kata_file>.\n   The <kata_file> has to include the whole source code of the kata.\n   The run will be captured into the newest session dir in the .codersdojo dir.\n   Usually this command is used after a session dir has been created with the init-session command.\n"
end

#show_help_init_sessionObject



108
109
110
111
112
113
114
115
# File 'lib/console_view.rb', line 108

def show_help_init_session
  show "\ninit-session\n   Create a new session dir in the .codersdojo dir.\n   Usually this command is used before using capture-single-run.\n"
end

#show_help_setupObject



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 "    \nsetup <framework> <kata_file>  \n   Setup the environment for the kata for the given framework and kata file.\n   The <kata_file> is the one file that will contain the source code of the code kata.\n   If <kata_file> does not have an extension it will be added automatically \n   - except if <framework> is ??? (see below).\n   By now <framework> is one of these:\n\#{templates}\n   Use ??? as framework if your framework isn't in the list.\n\nExample:\n   :%/%dojo%/%my_kata$ \#{current_command_path} setup ruby.test-unit prime\n       Setup the the environment for executing a code kata in kata file 'prime' with Ruby and test/unit.\n"
end

#show_help_startObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/console_view.rb', line 78

def show_help_start
  show "  \nstart <shell_command> <kata_file>  \n   Start the continuous test runner, that runs <shell_command> whenever <kata_file>\n   changes. The <kata_file> has to include the whole source code of the kata.\n   Whenever the test runner is started, it creates a new session directory in the \n   directory .codersdojo where it logs the steps of the kata.\n"
end

#show_help_unknown(command) ⇒ Object



146
147
148
149
150
# File 'lib/console_view.rb', line 146

def show_help_unknown command
  show "Command \#{command} not known. Try '\#{current_command_path} help' to list the supported commands.\n"
end

#show_help_uploadObject



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 "  \nupload                      \n   Upload the newest kata session in .codersdojo to codersdojo.com.\n   After the kata is uploaded the browser is started with the URL of the uploaded kata.\n\nupload <session_directory>  \n   Upload the kata <session_directory> to codersdojo.com. \n   <session_directory> is relative to the working directory.\n\nExamples:\n   :%/%dojo%/%my_kata$ \#{current_command_path} upload\n       Upload the newest kata located in directory \".codersdojo\" to codersdojo.com.\n   :%/%dojo%/%my_kata$ \#{current_command_path} upload .codersdojo%/%2010-11-02_16-21-53\n       Upload the kata located in directory \".codersdojo%/%2010-11-02_16-21-53\" to codersdojo.com.\n"
end

#show_help_upload_no_openObject



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 "\nupload-no-open                      \n   Upload the newest kata session in .codersdojo to codersdojo.com.\n\nupload-no-opem <session_directory>  \n   Upload the kata <session_directory> to codersdojo.com. \n   <session_directory> is relative to the working directory.\n\nExamples:\n   :%/%dojo%/%my_kata$ \#{current_command_path} upload-no-open\n       Upload the newest kata located in directory \".codersdojo\" to codersdojo.com.\n   :%/%dojo%/%my_kata$ \#{current_command_path} upload-no-open .codersdojo%/%2010-11-02_16-21-53\n       Upload the kata located in directory \".codersdojo%/%2010-11-02_16-21-53\" to codersdojo.com.\n"
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 "!!! WTF? \n!!! An internal server error occurred. This probably means that we sucked and there is\n!!! a bug. An error log was written to \#{log_file_name}.\n!!! Please help us to fix the bug and send us the log file via email: [email protected]\n"
end

#show_kata_exit_messageObject



202
203
204
205
206
207
208
209
210
211
# File 'lib/console_view.rb', line 202

def show_kata_exit_message
  show "\nYou finished your kata. Choose your next action:\n g) Revert to last green state.\n u) Upload the kata to http://www.codersdojo.com.\n e) Exit without uploading.\n r) Resume the kata.\n" 
end

#show_kata_upload_hintObject



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_toObject



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 "Property file \#{filename} is missing.\nMaybe you created the directory structure with an older version of CodersDojo?\nRecreate the directory structure with the current version with 'codersdojo setup ...'.\n"
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 show_run_once_message 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 show_unknwon_command_message 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_usageObject



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 "Usage: \#{current_command_path} command [options]\nCommands:\n help, -h, --help                     Print this help text.\n help <command>                       See the details of the command.\n xhelp                                Print help text for advanced commands.\n setup <framework> <kata_file>        Setup the environment for running the kata.\n upload-zip [<session_dir>]           Upload session as a ZIP file (beta feature)\n upload [<session_dir>]               Upload the kata to http://www.codersdojo.org and open the kata in a browser.\n upload-no-open [<session_dir>]       Upload the kata to http://www.codersdojo.org\n\nReport bugs to <[email protected]>\n"
end