Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #3 from markryall/master

some initial changes to add support for getting starting_points for forks
  • Loading branch information...
commit 33aea5cfebbbcff2f0dff27d36a2ae25306382fc 2 parents a200414 + 9752b64
Adrian Mowat authored September 21, 2011
8  retreat_gem/bin/retreat
... ...
@@ -1,5 +1,7 @@
1 1
 #!/usr/bin/env ruby
2 2
 
  3
+$: << File.dirname(__FILE__)+'/../lib'
  4
+
3 5
 require 'coderetreat/retreat'
4 6
 
5 7
 include CodeRetreat
@@ -36,11 +38,11 @@ action = ARGV.shift
36 38
 begin
37 39
   case
38 40
     when action == "info"
39  
-      Actions::Info.run!
  41
+      Actions::Info.run!(ARGV)
40 42
     when action == "install"
41  
-      Actions::Install.run!
  43
+      Actions::Install.run!(ARGV)
42 44
     when action == "update"
43  
-      Actions::Update.run!
  45
+      Actions::Update.run!(ARGV)
44 46
     when action == "start"
45 47
       Actions::Start.run!(ARGV)      
46 48
     else
107  retreat_gem/lib/coderetreat/retreat.rb
@@ -20,7 +20,7 @@ def initialize(*elements)
20 20
       relative_path = File.join(*elements)
21 21
       @path = File.expand_path(relative_path)
22 22
     end
23  
-    
  23
+
24 24
     def_file_op :exists?
25 25
     def_file_op :directory?
26 26
     def_file_op :file?
@@ -76,79 +76,96 @@ module Actions
76 76
     class Action
77 77
       def initialize
78 78
         @home = Path.new(Etc.getpwuid.dir, '.retreat')
79  
-        @local_repo = Path.new(Etc.getpwuid.dir, '.retreat', 'coderetreat')
80  
-        @source_repo = "https://github.com/coreyhaines/coderetreat.git"
81  
-        @starting_points = @local_repo.join("starting_points")
  79
+      end
  80
+
  81
+      def default_user
  82
+        'coreyhaines'
  83
+      end
  84
+
  85
+      def repo_url_for user
  86
+        "https://github.com/#{user}/coderetreat.git"
  87
+      end
  88
+  
  89
+      def repo_path user
  90
+        repo_path = @home.join user
  91
+        unless repo_path.exists?
  92
+          puts "Pulling #{user}/coderetreat repo into #{repo_path}..."
  93
+          Git.clone repo_url_for(user), repo_path
  94
+          puts "\nInstallation completed!  Here is some information..."              
  95
+        end
  96
+        repo_path
  97
+      end
  98
+
  99
+      def language user, language
  100
+        repo_path(user).join('starting_points', language)
  101
+      end
  102
+
  103
+      def languages user
  104
+        repo_path(user).join('starting_points').ls.map{|path| path.basename}
82 105
       end
83 106
     end
84  
-    
  107
+
85 108
     class Start < Action
86 109
       def self.run!(args)
87 110
         new(args).run!
88 111
       end
89  
-      
  112
+
90 113
       def initialize(args)
91 114
         super()
92  
-        @language = args[0]
93  
-        @source = @starting_points.join(@language)
  115
+        @user, @language = args[0].split('/')
  116
+        @user, @language = default_user, @user unless @language
94 117
         @target = args[1] ? Path.new(args[1]) : Path.new('.')
95 118
       end
96  
-      
  119
+  
97 120
       def run!
98 121
         validate_environment!
99  
-        @source.copy_to(@target)
  122
+        language(@user, @language).copy_to(@target)
100 123
         puts "Created #{@language} iteration starting point at #{@target}"
101 124
       end
102 125
       
103 126
       def validate_environment!
104  
-        raise EnvError.new("No sources found.  Try running 'retreat install' first") unless @source.directory?
105 127
         raise EnvError.new("Cannot create #{@target}") unless @target.dirname.writable?
106 128
       end
107 129
     end
108 130
     
109 131
     class Install < Action
110  
-      def self.run!
111  
-        new.run!
  132
+      def self.run!(args)
  133
+        new(args).run!
  134
+      end
  135
+
  136
+      def initialize(args)
  137
+        super()
  138
+        @user = args[0] || default_user
112 139
       end
113 140
 
114 141
       def run!
115  
-        validate_environment!
116  
-        puts "Pulling coderetreat repo into #{@local_repo}..."
117  
-        Git.clone @source_repo, @local_repo
118  
-        puts "\nInstallation completed!  Here is some information..."        
119  
-        Info.run!
  142
+        repo_path @user
  143
+        Info.run! [@user]
120 144
         puts "\nRun 'retreat start <language> [location]' to start a new iteration"
121 145
       end
122  
-      
123  
-      def validate_environment!
124  
-        if @local_repo.exists? 
125  
-          raise EnvError.new("retreat has already been installed.  Run 'retreat update' to get the latest starting points.")
126  
-        end
127  
-      end
128 146
     end
129  
-    
  147
+
130 148
     class Update < Action
131  
-      def self.run!
132  
-        new.run!
133  
-      end 
134  
-      
135  
-      def run!
136  
-        validate_environment!
137  
-        puts "Updating sources at #{@local_repo}"
138  
-        Git.pull @local_repo
  149
+      def self.run!(args)
  150
+        new(args)
139 151
       end
140  
-      
141  
-      def validate_environment!
142  
-        raise EnvError.new("retreat is not installed.  Run 'retreat install' to get started.") unless @local_repo.exists? 
  152
+
  153
+      def initialize(args)
  154
+        super()
  155
+        @user = args[0] || default_user
  156
+        puts "Updating sources at #{repo_path @user}"
  157
+        Git.pull repo_path(@user)
143 158
       end
144 159
     end
145  
-    
  160
+
146 161
     class Info < Action
147  
-      def self.run!
148  
-        new.run!
  162
+      def self.run!(args)
  163
+        new(args)
149 164
       end
150 165
 
151  
-      def run!
  166
+      def initialize(args)
  167
+        super()
  168
+        @user = args[0] || default_user
152 169
         result =<<EOS
153 170
         
154 171
 #{message}
@@ -158,17 +175,13 @@ def run!
158 175
       
159 176
       def message
160 177
         result =<<EOS
161  
-  Source Repo: #{@source_repo}
162  
-  Local Repo: #{@local_repo}
163  
-  Languages Available: #{languages.join(", ")}
  178
+  Source Repo: #{repo_url_for @user}
  179
+  Local Repo: #{repo_path @user}
  180
+  Languages Available: #{languages(@user).join(", ")}
164 181
 EOS
165 182
      
166 183
       result
167 184
       end
168  
-      
169  
-      def languages
170  
-        @starting_points.ls.map{|path| path.basename}
171  
-      end
172 185
     end
173 186
   end
174 187
 end
3  starting_points/intercal/readme.txt
... ...
@@ -0,0 +1,3 @@
  1
+Good luck.
  2
+
  3
+You're really going to need it.

0 notes on commit 33aea5c

Please sign in to comment.
Something went wrong with that request. Please try again.