Skip to content

Commit 89457e2

Browse files
committed
initial commit
0 parents  commit 89457e2

10 files changed

Lines changed: 356 additions & 0 deletions

File tree

‎Gemfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gemspec

‎Gemfile.lock‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
PATH
2+
remote: .
3+
specs:
4+
code (0.0.1)
5+
gli (= 2.8.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
aruba (0.5.3)
11+
childprocess (>= 0.3.6)
12+
cucumber (>= 1.1.1)
13+
rspec-expectations (>= 2.7.0)
14+
builder (3.2.2)
15+
childprocess (0.3.9)
16+
ffi (~> 1.0, >= 1.0.11)
17+
cucumber (1.3.8)
18+
builder (>= 2.1.2)
19+
diff-lcs (>= 1.1.3)
20+
gherkin (~> 2.12.1)
21+
multi_json (>= 1.7.5, < 2.0)
22+
multi_test (>= 0.0.2)
23+
diff-lcs (1.2.4)
24+
ffi (1.9.0)
25+
gherkin (2.12.1)
26+
multi_json (~> 1.3)
27+
gli (2.8.0)
28+
json (1.8.0)
29+
multi_json (1.8.0)
30+
multi_test (0.0.2)
31+
rake (10.1.0)
32+
rdoc (4.0.1)
33+
json (~> 1.4)
34+
rspec-expectations (2.14.2)
35+
diff-lcs (>= 1.1.3, < 2.0)
36+
37+
PLATFORMS
38+
ruby
39+
40+
DEPENDENCIES
41+
aruba
42+
code!
43+
rake
44+
rdoc

‎README.rdoc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
= code
2+
3+
Describe your project here
4+
5+
:include:code.rdoc
6+

‎Rakefile‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'rake/clean'
2+
require 'rubygems'
3+
require 'rubygems/package_task'
4+
require 'rdoc/task'
5+
require 'cucumber'
6+
require 'cucumber/rake/task'
7+
Rake::RDocTask.new do |rd|
8+
rd.main = "README.rdoc"
9+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10+
rd.title = 'Your application title'
11+
end
12+
13+
spec = eval(File.read('code.gemspec'))
14+
15+
Gem::PackageTask.new(spec) do |pkg|
16+
end
17+
CUKE_RESULTS = 'results.html'
18+
CLEAN << CUKE_RESULTS
19+
desc 'Run features'
20+
Cucumber::Rake::Task.new(:features) do |t|
21+
opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22+
opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23+
t.cucumber_opts = opts
24+
t.fork = false
25+
end
26+
27+
desc 'Run features tagged as work-in-progress (@wip)'
28+
Cucumber::Rake::Task.new('features:wip') do |t|
29+
tag_opts = ' --tags ~@pending'
30+
tag_opts = ' --tags @wip'
31+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32+
t.fork = false
33+
end
34+
35+
task :cucumber => :features
36+
task 'cucumber:wip' => 'features:wip'
37+
task :wip => 'features:wip'
38+
require 'rake/testtask'
39+
Rake::TestTask.new do |t|
40+
t.libs << "test"
41+
t.test_files = FileList['test/*_test.rb']
42+
end
43+
44+
task :default => [:test,:features]

‎bin/code‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env ruby
2+
require 'gli'
3+
begin # XXX: Remove this begin/rescue before distributing your app
4+
require 'code'
5+
rescue LoadError
6+
STDERR.puts "In development, you need to use `bundle exec bin/code` to run your app"
7+
STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8+
STDERR.puts "Feel free to remove this message from bin/code now"
9+
exit 64
10+
end
11+
12+
require 'code/git'
13+
14+
include GLI::App
15+
16+
program_desc 'The Coderly Toolbelt'
17+
18+
version Code::VERSION
19+
20+
desc 'Describe some switch here'
21+
switch [:s,:switch]
22+
23+
desc 'Describe start here'
24+
arg_name 'Start a new feature'
25+
command :start do |c|
26+
c.action do |global_options, options, (feature_name)|
27+
$git.start feature_name
28+
end
29+
end
30+
31+
desc 'Describe publish here'
32+
arg_name 'Describe arguments to publish here'
33+
command :publish do |c|
34+
c.action do |global_options, options, args|
35+
$git.publish
36+
end
37+
end
38+
39+
desc 'Describe finish here'
40+
arg_name 'Describe arguments to finish here'
41+
command :finish do |c|
42+
c.action do |global_options, options, args|
43+
$git.finish
44+
end
45+
end
46+
47+
desc 'Describe cancel here'
48+
arg_name 'Describe arguments to cancel here'
49+
command :cancel do |c|
50+
c.action do |global_options, options, args|
51+
$git.cancel
52+
end
53+
end
54+
55+
pre do |global, command, options, args|
56+
$git = Code::Git.new
57+
true
58+
end
59+
60+
post do |global,command,options,args|
61+
# Post logic here
62+
# Use skips_post before a command to skip this
63+
# block on that command only
64+
end
65+
66+
on_error do |exception|
67+
# Error logic here
68+
# return false to skip default error handling
69+
true
70+
end
71+
72+
exit run(ARGV)

‎code.gemspec‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Ensure we require the local version and not one we might have installed already
2+
require File.join([File.dirname(__FILE__),'lib','code','version.rb'])
3+
spec = Gem::Specification.new do |s|
4+
s.name = 'code'
5+
s.version = Code::VERSION
6+
s.author = 'Venkat'
7+
s.email = 'venkat@coderly.com'
8+
s.homepage = 'http://www.coderly.com'
9+
s.platform = Gem::Platform::RUBY
10+
s.summary = 'Our command line toolbelt for common tasks'
11+
12+
# Add your other files here if you make them
13+
s.files = %w(
14+
bin/code
15+
lib/code/version.rb
16+
lib/code.rb
17+
)
18+
19+
s.require_paths << 'lib'
20+
s.has_rdoc = true
21+
s.extra_rdoc_files = ['README.rdoc','code.rdoc']
22+
s.rdoc_options << '--title' << 'code' << '--main' << 'README.rdoc' << '-ri'
23+
s.bindir = 'bin'
24+
s.executables << 'code'
25+
s.add_development_dependency('rake')
26+
s.add_development_dependency('rdoc')
27+
s.add_development_dependency('aruba')
28+
s.add_runtime_dependency('gli','2.8.0')
29+
end

‎code.rdoc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
= code
2+
3+
Generate this with
4+
code rdoc
5+
After you have described your command line interface

‎lib/code.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'code/version.rb'
2+
3+
# Add requires for other files you add to your project here, so
4+
# you just need to require this one file in your bin file

‎lib/code/git.rb‎

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
module Code
2+
3+
class Git
4+
5+
COLORS = {black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, teal: 36}
6+
7+
def start(feature)
8+
ensure_feature_missing! feature
9+
10+
pull main_branch
11+
checkout main_branch unless on_main_branch?
12+
13+
create_branch feature
14+
checkout feature
15+
end
16+
17+
def cancel
18+
if on_main_branch?
19+
puts "Nothing to cancel (already on #{main_branch})"
20+
else
21+
branch = current_branch
22+
checkout main_branch
23+
delete_branch branch, force: true
24+
end
25+
end
26+
27+
def publish
28+
ensure_clean_slate!
29+
push current_branch
30+
compare_in_browser current_branch
31+
end
32+
33+
def compare_in_browser(branch)
34+
exec "hub compare #{branch}"
35+
end
36+
37+
def finish
38+
branch = current_branch
39+
40+
checkout main_branch
41+
fetch
42+
pull main_branch
43+
44+
delete_branch branch
45+
end
46+
47+
def files_changed?
48+
diff = `git diff --name-status`.strip
49+
diff != ''
50+
end
51+
52+
def push(branch)
53+
call "push origin #{branch}"
54+
end
55+
56+
def checkout(branch)
57+
call "checkout #{branch}"
58+
end
59+
60+
def fetch
61+
call 'fetch'
62+
end
63+
64+
def create_branch(branch)
65+
call "branch #{branch}"
66+
end
67+
68+
def delete_branch(branch, force: false)
69+
ensure_safe_branch! branch
70+
71+
flag = force ? '-D' : '-d'
72+
call "branch #{flag} #{branch}"
73+
end
74+
75+
def current_branch
76+
`git symbolic-ref HEAD --short`.strip
77+
end
78+
79+
def main_branch
80+
'development'
81+
end
82+
83+
def on_main_branch?
84+
on_branch? main_branch
85+
end
86+
87+
def on_branch? branch
88+
current_branch == branch
89+
end
90+
91+
def branch_exists?(branch)
92+
ref = `git show-ref refs/heads/#{branch}`.strip
93+
ref != ''
94+
end
95+
alias_method :feature_exists?, :branch_exists?
96+
97+
def pull(branch)
98+
call "pull origin #{branch}"
99+
end
100+
101+
def call(params)
102+
exec "git #{params}"
103+
end
104+
105+
def color(script, color)
106+
value = COLORS[color]
107+
"\033[0;#{value}m" + script + "\033[m"
108+
end
109+
110+
def green(script)
111+
color script, :green
112+
end
113+
114+
def red(script)
115+
color script, :magenta
116+
end
117+
118+
def ensure_safe_branch!(branch)
119+
error "branch #{branch} is protected" if protected_branch? branch
120+
end
121+
122+
def protected_branch? branch
123+
%w{master development}.include? branch
124+
end
125+
126+
def ensure_feature_missing!(feature)
127+
error "The #{feature} feature already exists" if feature_exists?(feature)
128+
end
129+
130+
def ensure_clean_slate!
131+
if files_changed?
132+
error "Please stash or commit your code"
133+
end
134+
end
135+
136+
def error(message)
137+
abort red(message)
138+
end
139+
140+
def exec(script)
141+
puts green(script)
142+
system script
143+
end
144+
145+
end
146+
147+
end

‎lib/code/version.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Code
2+
VERSION = '0.0.1'
3+
end

0 commit comments

Comments
 (0)