homesteading 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,105 +1,87 @@
1
- class Homesteading
2
- class Apps
3
- class << self
1
+ require "homesteading/command"
4
2
 
5
- def default
6
- puts
3
+ module Homesteading
4
+ class Apps < Command
5
+ register "apps"
7
6
 
8
- constellation_path = Dir.pwd
9
- publisher_apps = []
10
- nonpublisher_apps = []
7
+ def default
8
+ puts
11
9
 
12
- Dir.glob("#{Dir.pwd}/homesteading-*/").each do |directory|
13
- app = directory.split("/").last.sub(/homesteading-/, "").downcase
14
- app_file_path = directory + "app.json"
10
+ constellation_path = Dir.pwd
11
+ publisher_apps = []
12
+ nonpublisher_apps = []
15
13
 
16
- app_keywords = []
17
- if File.exist?(app_file_path)
18
- app_file = JSON.parse(File.read(app_file_path))
19
- app_keywords = app_file["keywords"]
20
- end
14
+ Dir.glob("#{Dir.pwd}/homesteading-*/").each do |directory|
15
+ app = directory.split("/").last.sub(/homesteading-/, "").downcase
16
+ app_file_path = directory + "app.json"
21
17
 
22
- if app_keywords.include?("hs:publisher")
23
- publisher_apps << app
24
- else
25
- nonpublisher_apps << app
26
- end
18
+ app_keywords = []
19
+ if File.exist?(app_file_path)
20
+ app_file = JSON.parse(File.read(app_file_path))
21
+ app_keywords = app_file["keywords"]
27
22
  end
28
23
 
29
- unless publisher_apps.empty?
30
- puts "* Publisher Apps"
31
- publisher_apps.each do |app|
32
- puts " #{app}"
33
- end
34
- puts
24
+ if app_keywords.include?("hs:publisher")
25
+ publisher_apps << app
26
+ else
27
+ nonpublisher_apps << app
35
28
  end
29
+ end
36
30
 
37
- unless nonpublisher_apps.empty?
38
- puts "* Non-Publisher Apps"
39
- nonpublisher_apps.each do |app|
40
- puts " #{app}"
41
- end
31
+ unless publisher_apps.empty?
32
+ puts "* Publisher Apps"
33
+ publisher_apps.each do |app|
34
+ puts " #{app}"
42
35
  end
43
-
44
36
  puts
45
37
  end
46
38
 
47
- def create
48
- puts
49
- options = parse_options
50
-
51
- if options[:app].nil? && options[:app].nil?
52
- puts "* This requires an '--app' or '--url'"
53
- puts "* Example:"
54
- puts " homesteading apps:create --app note"
55
- puts " homesteading apps:create --url git@github.com:homesteading/homesteading-note.git"
56
- puts
57
- exit
39
+ unless nonpublisher_apps.empty?
40
+ puts "* Non-Publisher Apps"
41
+ nonpublisher_apps.each do |app|
42
+ puts " #{app}"
58
43
  end
44
+ end
59
45
 
60
- git_url = if options[:app]
61
- "git@github.com:homesteading/homesteading-#{options[:app]}.git"
62
- else
63
- options[:url]
64
- end
46
+ puts
47
+ end
65
48
 
66
- app_dir = git_url.split("/").last.split(".git").first
49
+ def create
50
+ puts
51
+ options = parse_options
67
52
 
68
- if File.exist?(app_dir)
69
- if options[:skip]
70
- unless options[:quiet]
71
- puts "* #{app_dir} already exists"
72
- puts "* Skipping homesteading-#{options[:app]}"
73
- end
74
- elsif options[:force]
75
- unless options[:quiet]
76
- puts "* #{app_dir} already exists"
77
- puts "* Removing homesteading-#{options[:app]}"
78
- end
53
+ if options[:app].nil? && options[:app].nil?
54
+ puts "* This requires an '--app' or '--url'"
55
+ puts "* Example:"
56
+ puts " homesteading apps:create --app note"
57
+ puts " homesteading apps:create --url git@github.com:homesteading/homesteading-note.git"
58
+ puts
59
+ exit
60
+ end
79
61
 
80
- unless options[:pretend]
81
- FileUtils.rm_rf app_dir
82
- end
62
+ git_url = if options[:app]
63
+ "git@github.com:homesteading/homesteading-#{options[:app]}.git"
64
+ else
65
+ options[:url]
66
+ end
83
67
 
84
- unless options[:quiet]
85
- if options[:app]
86
- puts "* Cloning homesteading app from GitHub: #{options[:app]}"
87
- else
88
- puts "* Cloning from: #{options[:url]}"
89
- end
90
- end
68
+ app_dir = git_url.split("/").last.split(".git").first
91
69
 
92
- unless options[:pretend]
93
- system "git clone #{git_url}"
94
- end
95
- else
96
- unless options[:quiet]
97
- puts "* #{app_dir} already exists"
98
- puts "* TODO gets user input on what to do about the conflict"
99
- end
70
+ if File.exist?(app_dir)
71
+ if options[:skip]
72
+ unless options[:quiet]
73
+ puts "* #{app_dir} already exists"
74
+ puts "* Skipping homesteading-#{options[:app]}"
75
+ end
76
+ elsif options[:force]
77
+ unless options[:quiet]
78
+ puts "* #{app_dir} already exists"
79
+ puts "* Removing homesteading-#{options[:app]}"
100
80
  end
101
81
 
102
- else
82
+ unless options[:pretend]
83
+ FileUtils.rm_rf app_dir
84
+ end
103
85
 
104
86
  unless options[:quiet]
105
87
  if options[:app]
@@ -112,227 +94,245 @@ class Homesteading
112
94
  unless options[:pretend]
113
95
  system "git clone #{git_url}"
114
96
  end
97
+ else
98
+ unless options[:quiet]
99
+ puts "* #{app_dir} already exists"
100
+ puts "* TODO gets user input on what to do about the conflict"
101
+ end
115
102
  end
116
103
 
117
- puts
118
- end
104
+ else
119
105
 
120
- def destroy
121
- puts
122
- options = parse_options
106
+ unless options[:quiet]
107
+ if options[:app]
108
+ puts "* Cloning homesteading app from GitHub: #{options[:app]}"
109
+ else
110
+ puts "* Cloning from: #{options[:url]}"
111
+ end
112
+ end
123
113
 
124
- if options[:app].nil?
125
- puts "* '--app APP' is required for this command"
126
- puts
127
- exit
114
+ unless options[:pretend]
115
+ system "git clone #{git_url}"
128
116
  end
117
+ end
129
118
 
130
- app = options[:app].downcase
131
- constellation_path = Dir.pwd
132
- app_dir = "#{constellation_path}/homesteading-#{app}"
119
+ puts
120
+ end
133
121
 
134
- unless File.exist?(app_dir)
135
- puts "* #{app} does not exist"
136
- puts "* Did you mean one of these?"
137
- Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
138
- puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
139
- end
140
- puts
141
- exit
122
+ def destroy
123
+ puts
124
+ options = parse_options
125
+
126
+ if options[:app].nil?
127
+ puts "* '--app APP' is required for this command"
128
+ puts
129
+ exit
130
+ end
131
+
132
+ app = options[:app].downcase
133
+ constellation_path = Dir.pwd
134
+ app_dir = "#{constellation_path}/homesteading-#{app}"
135
+
136
+ unless File.exist?(app_dir)
137
+ puts "* #{app} does not exist"
138
+ puts "* Did you mean one of these?"
139
+ Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
140
+ puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
142
141
  end
142
+ puts
143
+ exit
144
+ end
143
145
 
144
- if options[:confirm] == app || options[:confirm] == "homesteading-#{app}"
146
+ if options[:confirm] == app || options[:confirm] == "homesteading-#{app}"
147
+ puts "* Destroying #{app} permananently..."
148
+ FileUtils.rm_rf app_dir
149
+ puts "* ...done"
150
+ else
151
+ puts "! WARNING: Potentially Destructive Action"
152
+ puts "! This command will destroy #{app}"
153
+ puts "! To proceed, type '#{app}' or re-run this command with '--confirm #{app}'"
154
+ puts
155
+ confirmation_input = gets.chomp
156
+ puts
157
+
158
+ if confirmation_input == app
145
159
  puts "* Destroying #{app} permananently..."
146
160
  FileUtils.rm_rf app_dir
147
161
  puts "* ...done"
148
162
  else
149
- puts "! WARNING: Potentially Destructive Action"
150
- puts "! This command will destroy #{app}"
151
- puts "! To proceed, type '#{app}' or re-run this command with '--confirm #{app}'"
152
- puts
153
- confirmation_input = gets.chomp
154
- puts
155
-
156
- if confirmation_input == app
157
- puts "* Destroying #{app} permananently..."
158
- FileUtils.rm_rf app_dir
159
- puts "* ...done"
160
- else
161
- puts "! Confirmation did not match #{app}. Aborted."
162
- end
163
+ puts "! Confirmation did not match #{app}. Aborted."
163
164
  end
165
+ end
166
+
167
+ puts
168
+ end
164
169
 
170
+ def info
171
+ puts
172
+ options = parse_options
173
+
174
+ if options[:app].nil?
175
+ puts "* '--app APP' is required for this command"
165
176
  puts
177
+ exit
166
178
  end
167
179
 
168
- def info
169
- puts
170
- options = parse_options
180
+ app = options[:app].downcase
181
+ constellation_path = Dir.pwd
182
+ app_dir = "#{constellation_path}/homesteading-#{app}/"
183
+ app_file_path = app_dir + "app.json"
171
184
 
172
- if options[:app].nil?
173
- puts "* '--app APP' is required for this command"
185
+ if File.exist?(app_dir)
186
+ if File.exist?(app_file_path)
187
+ app_file = JSON.parse(File.read(app_file_path))
188
+ puts app_file.to_yaml
189
+ else
190
+ puts "* No app.json found for #{app}"
174
191
  puts
175
192
  exit
176
193
  end
194
+ else
195
+ puts "* #{app} does not exist"
196
+ puts "* Did you mean one of these?"
197
+ Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
198
+ puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
199
+ end
200
+ puts
201
+ exit
202
+ end
177
203
 
178
- app = options[:app].downcase
179
- constellation_path = Dir.pwd
180
- app_dir = "#{constellation_path}/homesteading-#{app}/"
181
- app_file_path = app_dir + "app.json"
204
+ puts
205
+ end
182
206
 
183
- if File.exist?(app_dir)
184
- if File.exist?(app_file_path)
185
- app_file = JSON.parse(File.read(app_file_path))
186
- puts app_file.to_yaml
187
- else
188
- puts "* No app.json found for #{app}"
189
- puts
190
- exit
191
- end
192
- else
193
- puts "* #{app} does not exist"
194
- puts "* Did you mean one of these?"
195
- Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
196
- puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
197
- end
198
- puts
199
- exit
200
- end
207
+ def rename
208
+ puts
209
+ options = parse_options
201
210
 
211
+ if options[:app].nil?
212
+ puts "* '--app APP' is required for this command"
202
213
  puts
214
+ exit
203
215
  end
204
216
 
205
- def rename
217
+ new_name = ARGV.shift
218
+ if new_name.nil?
219
+ puts "* New app name is required for this command"
220
+ puts "* Example:"
221
+ puts " homesteading apps:rename status --app note"
206
222
  puts
207
- options = parse_options
223
+ exit
224
+ end
208
225
 
209
- if options[:app].nil?
210
- puts "* '--app APP' is required for this command"
211
- puts
212
- exit
226
+ app = options[:app].downcase
227
+ constellation_path = Dir.pwd
228
+ app_dir = "#{constellation_path}/homesteading-#{app}"
229
+ new_app_dir = "#{constellation_path}/homesteading-#{new_name}"
230
+
231
+ if File.exist?(app_dir)
232
+ puts "* Renaming #{app} to #{new_name}..."
233
+ FileUtils.mv app_dir, new_app_dir
234
+ puts "* ...done"
235
+ else
236
+ puts "* #{app} does not exist"
237
+ puts "* Did you mean one of these?"
238
+ Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
239
+ puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
213
240
  end
241
+ puts
242
+ exit
243
+ end
214
244
 
215
- new_name = ARGV.shift
216
- if new_name.nil?
217
- puts "* New app name is required for this command"
218
- puts "* Example:"
219
- puts " homesteading apps:rename status --app note"
220
- puts
221
- exit
222
- end
245
+ puts
246
+ end
223
247
 
224
- app = options[:app].downcase
225
- constellation_path = Dir.pwd
226
- app_dir = "#{constellation_path}/homesteading-#{app}"
227
- new_app_dir = "#{constellation_path}/homesteading-#{new_name}"
228
-
229
- if File.exist?(app_dir)
230
- puts "* Renaming #{app} to #{new_name}..."
231
- FileUtils.mv app_dir, new_app_dir
232
- puts "* ...done"
233
- else
234
- puts "* #{app} does not exist"
235
- puts "* Did you mean one of these?"
236
- Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
237
- puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
238
- end
239
- puts
240
- exit
241
- end
248
+ def reroute
249
+ puts
250
+ options = parse_options
242
251
 
252
+ if options[:app].nil?
253
+ puts "* '--app APP' is required for this command"
243
254
  puts
255
+ exit
244
256
  end
245
257
 
246
- def reroute
258
+ new_route = ARGV.shift
259
+ if new_route.nil?
260
+ puts "* New app route is required for this command"
261
+ puts "* Example:"
262
+ puts " homesteading apps:reroute statuses --app note"
247
263
  puts
248
- options = parse_options
249
-
250
- if options[:app].nil?
251
- puts "* '--app APP' is required for this command"
252
- puts
253
- exit
254
- end
255
-
256
- new_route = ARGV.shift
257
- if new_route.nil?
258
- puts "* New app route is required for this command"
259
- puts "* Example:"
260
- puts " homesteading apps:reroute statuses --app note"
261
- puts
262
- exit
263
- end
264
+ exit
265
+ end
264
266
 
265
- app = options[:app].downcase
266
- constellation_path = Dir.pwd
267
- app_dir = "#{constellation_path}/homesteading-#{app}/"
268
- app_file_path = app_dir + "app.json"
267
+ app = options[:app].downcase
268
+ constellation_path = Dir.pwd
269
+ app_dir = "#{constellation_path}/homesteading-#{app}/"
270
+ app_file_path = app_dir + "app.json"
269
271
 
270
- if File.exist?(app_dir)
271
- if File.exist?(app_file_path)
272
- app_file = JSON.parse(File.read(app_file_path))
273
- app_file["routes"]["path"] = new_route
272
+ if File.exist?(app_dir)
273
+ if File.exist?(app_file_path)
274
+ app_file = JSON.parse(File.read(app_file_path))
275
+ app_file["routes"]["path"] = new_route
274
276
 
275
- puts "* Rerouting note to /statuses..."
276
- new_app_file = JSON.pretty_generate(app_file)
277
- File.write(app_file_path, new_app_file)
278
- puts "* ...done"
279
- else
280
- puts "* No app.json found for #{app}"
281
- puts
282
- exit
283
- end
277
+ puts "* Rerouting note to /statuses..."
278
+ new_app_file = JSON.pretty_generate(app_file)
279
+ File.write(app_file_path, new_app_file)
280
+ puts "* ...done"
284
281
  else
285
- puts "* #{app} does not exist"
286
- puts "* Did you mean one of these?"
287
- Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
288
- puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
289
- end
282
+ puts "* No app.json found for #{app}"
290
283
  puts
291
284
  exit
292
285
  end
293
-
286
+ else
287
+ puts "* #{app} does not exist"
288
+ puts "* Did you mean one of these?"
289
+ Dir.glob("#{Dir.pwd}/homesteading-*/").each do |ff|
290
+ puts " - #{ff.split("/").last.sub(/homesteading-/, "")}"
291
+ end
294
292
  puts
293
+ exit
295
294
  end
296
295
 
297
- private
298
- def parse_options
299
- # Parse command line options
300
- options = {}
296
+ puts
297
+ end
301
298
 
302
- optparse = OptionParser.new do |opts|
303
- opts.on("-a", "--app APP", "Name of Homesteading app on GitHub") do |app|
304
- options[:app] = app
305
- end
299
+ private
300
+ def parse_options
301
+ # Parse command line options
302
+ options = {}
306
303
 
307
- opts.on("-c", "--confirm CONFIRM", "Confirm the app name to delete") do |confirm|
308
- options[:confirm] = confirm
309
- end
304
+ optparse = OptionParser.new do |opts|
305
+ opts.on("-a", "--app APP", "Name of Homesteading app on GitHub") do |app|
306
+ options[:app] = app
307
+ end
310
308
 
311
- opts.on("-f", "--force", "Overwrite apps that already exist") do |force|
312
- options[:force] = force
313
- end
309
+ opts.on("-c", "--confirm CONFIRM", "Confirm the app name to delete") do |confirm|
310
+ options[:confirm] = confirm
311
+ end
314
312
 
315
- opts.on("-p", "--pretend", "Run but do not make any changes") do |pretend|
316
- options[:pretend] = pretend
317
- end
313
+ opts.on("-f", "--force", "Overwrite apps that already exist") do |force|
314
+ options[:force] = force
315
+ end
318
316
 
319
- opts.on("-q", "--quiet", "Suppress status output") do |quiet|
320
- options[:quiet] = quiet
321
- end
317
+ opts.on("-p", "--pretend", "Run but do not make any changes") do |pretend|
318
+ options[:pretend] = pretend
319
+ end
322
320
 
323
- opts.on("-s", "--skip", "Skip apps that already exist") do |skip|
324
- options[:skip] = skip
325
- end
321
+ opts.on("-q", "--quiet", "Suppress status output") do |quiet|
322
+ options[:quiet] = quiet
323
+ end
326
324
 
327
- opts.on("-u", "--url URL", "URL of Homesteading app") do |url|
328
- options[:url] = url
329
- end
325
+ opts.on("-s", "--skip", "Skip apps that already exist") do |skip|
326
+ options[:skip] = skip
330
327
  end
331
328
 
332
- optparse.parse!
333
- options
329
+ opts.on("-u", "--url URL", "URL of Homesteading app") do |url|
330
+ options[:url] = url
331
+ end
334
332
  end
335
333
 
334
+ optparse.parse!
335
+ options
336
336
  end
337
337
  end
338
338
  end
@@ -1,36 +1,37 @@
1
- class Homesteading
2
- class Help
3
- class << self
4
- DEFAULT_HELP_DOC = "README"
1
+ require "homesteading/command"
5
2
 
6
- def default
7
- help_doc_path = if ARGV.empty?
8
- DEFAULT_HELP_DOC
9
- elsif ARGV.first.match(/:/)
10
- ARGV.first.sub(":", "-")
11
- else
12
- ARGV.first
13
- end
3
+ module Homesteading
4
+ class Help < Command
5
+ register "help", "h"
14
6
 
15
- print(help_doc_path)
16
- end
7
+ DEFAULT_HELP_DOC = "README"
17
8
 
18
- def print(path)
19
- # TODO better way?
20
- help_dir = File.expand_path("../../../../help/", __FILE__)
21
- file = "#{help_dir}/#{path}.md"
9
+ def default
10
+ help_doc_path = if ARGV.empty?
11
+ DEFAULT_HELP_DOC
12
+ elsif ARGV.first.match(/:/)
13
+ ARGV.first.sub(":", "-")
14
+ else
15
+ ARGV.first
16
+ end
22
17
 
23
- puts
24
- unless File.exist?(file)
25
- file = "#{help_dir}/#{DEFAULT_HELP_DOC}.md"
26
- puts "Unknown command. No help docs about that."
27
- puts
28
- end
18
+ print(help_doc_path)
19
+ end
20
+
21
+ def print(path)
22
+ # TODO better way?
23
+ help_dir = File.expand_path("../../../../help/", __FILE__)
24
+ file = "#{help_dir}/#{path}.md"
29
25
 
30
- puts File.read(file)
26
+ puts
27
+ unless File.exist?(file)
28
+ file = "#{help_dir}/#{DEFAULT_HELP_DOC}.md"
29
+ puts "Unknown command. No help docs about that."
31
30
  puts
32
31
  end
33
32
 
33
+ puts File.read(file)
34
+ puts
34
35
  end
35
36
  end
36
37
  end