1
1
module Commandable
2
-
2
+
3
3
# A helper to display the read me file and generate an example app
4
4
class AppController
5
- WIDGET_GITHUB ||= "://github.com/mikbe/widget"
6
5
7
6
class << self
8
7
extend Commandable
9
-
8
+
10
9
# Displays the readme file
11
10
command "displays the readme file" , :default
12
11
def readme
13
- `open #{ File . expand_path ( ( File . dirname ( __FILE__ ) + '/../../readme.markdown' ) ) } `
14
- end
15
-
16
- command "Downloads a fully working app demonstrating how\n to use Commandable with RSpec and Cucumber"
17
- # Creates a simple example app demonstrating a fully working app
18
- def widget ( path = "./widget" )
19
- # Test for Git
20
- unless git_installed?
21
- puts "Git must be installed to download Widget (You're a developer and you don't have Git installed?)"
22
- return
23
- end
24
- # Git already has all of its own error trapping so
25
- # it would be horrible coupling and duplication
26
- # of effort to do anything on my end for failures.
27
- puts "\n Unable to download Widget. You can find the souce code here:\n https#{ WIDGET_GITHUB } " unless download_widget ( path ) == 0
12
+ `open #{ File . expand_path ( ( File . dirname ( __FILE__ ) + '/../../readme.md' ) ) } `
28
13
end
29
14
30
- # Downloads Widget from the git repository
31
- # This is external to the widget command so it can be stubbed for testing
32
- def download_widget ( path )
33
- `git clone git#{ WIDGET_GITHUB } .git #{ path } `
34
- $?. exitstatus
35
- end
36
-
37
- # Checks to see if Git is installed
38
- # This is external to the widget command so it can be stubbed for testing
39
- def git_installed?
40
- !`git --version` . chomp . match ( /^git version/i ) . nil?
41
- end
42
-
43
15
command "Copies the test classes to a folder so\n you can see a bunch of small examples"
44
16
# Copies the test classes to a folder so you can see a bunch of small examples
45
17
def examples ( path = "./examples" )
@@ -49,30 +21,27 @@ def examples(path="./examples")
49
21
command "Will raise a programmer error, not a user error\n so you can see what happens when you have bad code"
50
22
# Causes an error so you can see what it will look like if you have an error in your code.
51
23
def error
52
- raise Exception , "An example of a non-user error caused by your bad code trapped in Commandable.execute() "
24
+ raise Exception , "An example of what an error looks like if you make a mistake using Commandable."
53
25
end
54
-
26
+
55
27
command "Application Version" , :xor
56
28
# Version
57
29
def v
58
30
puts "Commandable: #{ Commandable ::VERSION } "
59
31
end
60
32
command "Application Version" , :xor
61
33
alias :version :v
62
-
34
+
63
35
private
64
-
36
+
65
37
def copy_dir ( source , dest )
66
38
files = Dir . glob ( "#{ source } /**" )
67
39
mkdir_p dest
68
40
cp_r files , dest
69
41
end
70
42
71
-
72
43
end
73
-
74
-
75
-
44
+
76
45
end
77
-
46
+
78
47
end
0 commit comments