retreat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/retreat +54 -0
- data/lib/coderetreat/retreat.rb +150 -0
- data/retreat.gemspec +18 -0
- metadata +51 -0
data/bin/retreat
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'coderetreat/retreat'
|
4
|
+
|
5
|
+
include CodeRetreat
|
6
|
+
|
7
|
+
def usage
|
8
|
+
result = <<EOS
|
9
|
+
usage: #{__FILE__} action [command...]
|
10
|
+
----
|
11
|
+
Actions:
|
12
|
+
info : Prints information message
|
13
|
+
install : Downloads and installs starting point repo to ~/.retreat/retreat
|
14
|
+
update : Pulls latest langauge starting points from github source repo
|
15
|
+
start language [directory] : Starts a new iteration using 'language' in 'directory'
|
16
|
+
directory defaults to '.' if not specified
|
17
|
+
EOS
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def fail_with_error(message)
|
23
|
+
STDERR.puts message
|
24
|
+
exit 9
|
25
|
+
end
|
26
|
+
|
27
|
+
def fail_with_usage_error(message)
|
28
|
+
STDERR.puts message
|
29
|
+
STDERR.puts usage
|
30
|
+
exit 9
|
31
|
+
end
|
32
|
+
|
33
|
+
fail_with_usage_error "Error: No args passed" if ARGV.empty?
|
34
|
+
action = ARGV.shift
|
35
|
+
|
36
|
+
begin
|
37
|
+
case
|
38
|
+
when action == "info"
|
39
|
+
Actions::Info.run!
|
40
|
+
when action == "install"
|
41
|
+
Actions::Install.run!
|
42
|
+
when action == "update"
|
43
|
+
Actions::Update.run!
|
44
|
+
when action == "start"
|
45
|
+
Actions::Start.run!(ARGV)
|
46
|
+
else
|
47
|
+
raise UsageError.new("Error: unknown action '#{action}'")
|
48
|
+
end
|
49
|
+
rescue UsageError => ex
|
50
|
+
fail_with_usage_error "Error: #{ex}"
|
51
|
+
rescue EnvError => ex
|
52
|
+
fail_with_error "Error: #{ex}"
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'etc'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
module CodeRetreat
|
7
|
+
class UsageError < Exception; end
|
8
|
+
class EnvError < Exception; end
|
9
|
+
|
10
|
+
class Path
|
11
|
+
# Defines a delegator method to File
|
12
|
+
def self.def_file_op(name)
|
13
|
+
file_op = name.to_sym
|
14
|
+
define_method(file_op) do |*args|
|
15
|
+
File.send(file_op, @path, *args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(*elements)
|
20
|
+
relative_path = File.join(*elements)
|
21
|
+
@path = File.expand_path(relative_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def_file_op :exists?
|
25
|
+
def_file_op :directory?
|
26
|
+
def_file_op :file?
|
27
|
+
def_file_op :writable?
|
28
|
+
def_file_op :basename
|
29
|
+
|
30
|
+
def dirname
|
31
|
+
Path.new(File.dirname(@path))
|
32
|
+
end
|
33
|
+
|
34
|
+
def join(*elements)
|
35
|
+
Path.new(@path, *elements)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
@path.clone
|
40
|
+
end
|
41
|
+
|
42
|
+
def copy_to(target)
|
43
|
+
cp_r @path, target.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def ls
|
47
|
+
Dir["#{@path}/*"].map{|listing_item| Path.new(listing_item)}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Actions
|
52
|
+
class Action
|
53
|
+
def initialize
|
54
|
+
@home = Path.new(Etc.getpwuid.dir, '.retreat')
|
55
|
+
@local_repo = Path.new(Etc.getpwuid.dir, '.retreat', 'retreat')
|
56
|
+
@source_repo = "https://github.com/coreyhaines/coderetreat.git"
|
57
|
+
@starting_points = @local_repo.join("starting_points")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Start < Action
|
62
|
+
def self.run!(args)
|
63
|
+
new(args).run!
|
64
|
+
end
|
65
|
+
|
66
|
+
def initialize(args)
|
67
|
+
super()
|
68
|
+
@language = args[0]
|
69
|
+
@source = @starting_points.join(@language)
|
70
|
+
@target = args[1] ? Path.new(args[1]) : Path.new('.')
|
71
|
+
end
|
72
|
+
|
73
|
+
def run!
|
74
|
+
validate_environment!
|
75
|
+
@source.copy_to(@target)
|
76
|
+
puts "Created #{@language} iteration starting point at #{@target}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate_environment!
|
80
|
+
raise EnvError.new("No sources found. Try running 'retreat install' first") unless @source.directory?
|
81
|
+
raise EnvError.new("Cannot create #{@target}") unless @target.dirname.writable?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Install < Action
|
86
|
+
def self.run!
|
87
|
+
new.run!
|
88
|
+
end
|
89
|
+
|
90
|
+
def run!
|
91
|
+
validate_environment!
|
92
|
+
puts "Pulling coderetreat repo into #{@local_repo}..."
|
93
|
+
%x{git clone #{@source_repo} #{@local_repo}}
|
94
|
+
puts "\nInstallation completed! Here is some information..."
|
95
|
+
Info.run!
|
96
|
+
puts "\nRun 'retreat start <language> [location]' to start a new iteration"
|
97
|
+
end
|
98
|
+
|
99
|
+
def validate_environment!
|
100
|
+
if @local_repo.exists?
|
101
|
+
raise EnvError.new("retreat has already been installed. Run 'retreat update' to get the latest starting points.")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class Update < Action
|
107
|
+
def self.run!
|
108
|
+
new.run!
|
109
|
+
end
|
110
|
+
|
111
|
+
def run!
|
112
|
+
validate_environment!
|
113
|
+
puts "Updating sources at #{@local_repo}"
|
114
|
+
%x{git pull #{@local_repo}}
|
115
|
+
end
|
116
|
+
|
117
|
+
def validate_environment!
|
118
|
+
raise EnvError.new("retreat is not installed. Run 'retreat install' to get started.") unless @local_repo.exists?
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Info < Action
|
123
|
+
def self.run!
|
124
|
+
new.run!
|
125
|
+
end
|
126
|
+
|
127
|
+
def run!
|
128
|
+
result =<<EOS
|
129
|
+
|
130
|
+
#{message}
|
131
|
+
EOS
|
132
|
+
puts result
|
133
|
+
end
|
134
|
+
|
135
|
+
def message
|
136
|
+
result =<<EOS
|
137
|
+
Source Repo: #{@source_repo}
|
138
|
+
Local Repo: #{@local_repo}
|
139
|
+
Langauges Avilable: #{languages.join(",")}
|
140
|
+
EOS
|
141
|
+
|
142
|
+
result
|
143
|
+
end
|
144
|
+
|
145
|
+
def languages
|
146
|
+
@starting_points.ls.map{|path| path.basename}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/retreat.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
SPEC = Gem::Specification.new do |s|
|
4
|
+
s.name = "retreat"
|
5
|
+
s.version = '0.1.0'
|
6
|
+
s.author = "Adrian Mowat"
|
7
|
+
s.homepage = "https://github.com/coreyhaines/coderetreat"
|
8
|
+
s.summary = "Command line utilities for coderetreat"
|
9
|
+
s.description = <<EOS
|
10
|
+
retreat allows you to easily start new coderetreat iterations in different languges. Starting point "skeletons" are held in a git repo and copied as needed.
|
11
|
+
EOS
|
12
|
+
s.has_rdoc = false
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: retreat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrian Mowat
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-19 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'retreat allows you to easily start new coderetreat iterations in different
|
15
|
+
languges. Starting point "skeletons" are held in a git repo and copied as needed.
|
16
|
+
|
17
|
+
'
|
18
|
+
email:
|
19
|
+
executables:
|
20
|
+
- retreat
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- bin/retreat
|
25
|
+
- lib/coderetreat/retreat.rb
|
26
|
+
- retreat.gemspec
|
27
|
+
homepage: https://github.com/coreyhaines/coderetreat
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.8
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Command line utilities for coderetreat
|
51
|
+
test_files: []
|