Last active
August 29, 2015 14:05
-
-
Save LeShadow/a01a5e2809b1f87438bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: gitify [options]" | |
opts.on("-n", "--namespace=NAMESPACE", "Define the namespace of the repository. if this is empty, no namespace will be used.") do |namespace| | |
options[:namespace] = namespace | |
end | |
opts.on("-g", "--git=REPOSITORY", "Define the repository.git | Example: --git=test.git") do |git| | |
options[:git] = git | |
end | |
opts.on("-a", "--all", "Provision all branches. (Staging, Acc, Production, Master)") do |all| | |
options[:all] = all | |
end | |
opts.on("-br", "--branche=BRANCHES", "Branches split by a ,") do |branches| | |
options[:branches] = branches | |
end | |
opts.on("-p", "--projecttype=TYPE", "Type: drupal(didi) or general (capistano)") do |type| | |
options[:type] = type | |
end | |
opts.on("-d", "--directory=DIRECTORY", "The place where gitify has to create your structure") do |dir| | |
options[:dir] = dir | |
end | |
end.parse! | |
puts "lol" | |
#p options | |
branch_arr = [] | |
if options[:all] | |
branch_arr = ["staging","acc","production"] | |
elsif options[:branches].length > 0 | |
branch_arr = options[:branches].split(',') | |
else | |
puts "No branches defined. Will only provision master branch." | |
end | |
if options.has_key?("namespace".to_sym) | |
namespace = options[:namespace] + "/" | |
else | |
namespace = "" | |
end | |
command = "" | |
if options.has_key?("type".to_sym) && options.has_key?("dir".to_sym) | |
command = options[:type] + " " + options[:dir] | |
elsif options.has_key?("dir".to_sym) | |
command = options[:dir] | |
else | |
puts "You have to define at least your directory!" | |
exit | |
end | |
output_git_clone = `git clone [email protected]:#{namespace}#{options[:git]}` | |
if output_git_clone.include? "done" | |
output_projectify_master = ` cd #{options[:git].chop.chop.chop.chop};projectify #{command};git push origin master` | |
branch_arr.each do |branch| | |
output_branch = `git branch #{branch};git checkout #{branch};git push origin #{branch}` | |
end | |
else | |
puts "Something went horribly wrong." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment