code cleanup

This commit is contained in:
rkiel
2015-06-06 07:33:54 -04:00
parent db0a6f5501
commit 8f6feab7ea
6 changed files with 65 additions and 19 deletions

View File

@@ -13,6 +13,15 @@ module Feature
def initialize (argv) def initialize (argv)
@argv = argv @argv = argv
end end
def valid?
true
end
def help
exit
end
end end
end end

View File

@@ -7,31 +7,29 @@ require_relative './branch'
module Feature module Feature
class Commander class Commander
attr_reader :argv attr_reader :subcommand
def initialize (argv) def initialize (argv)
@argv = argv @subcommand = case argv[0]
when "start" then Feature::Start.new(argv)
when "end" then Feature::End.new(argv)
when "rebase" then Feature::Rebase.new(argv)
when "merge" then Feature::MergeTo.new(argv)
else Feature::Branch.new(argv)
end
end end
def valid? def valid?
true subcommand.valid?
end end
def help def help
exit subcommand.help
end end
def execute def execute
command = case argv[0] subcommand.execute
when "start" then Feature::Start.new(argv)
when "end" then Feature::End.new(argv)
when "rebase" then Feature::Rebase.new(argv)
when "merge" then Feature::MergeTo.new(argv)
else Feature::Branch.new(argv)
end
command.execute
end end
end end
end end

View File

@@ -3,9 +3,18 @@ require_relative './base'
module Feature module Feature
class End < Feature::Base class End < Feature::Base
def execute def valid?
error "USAGE: feature end" unless argv.size == 1 argv.size == 1
end
def help
puts
puts "USAGE: feature end"
puts
exit
end
def execute
parts = parse_branch(current_branch) parts = parse_branch(current_branch)
standard_branch = parts[:standard] standard_branch = parts[:standard]

View File

@@ -3,6 +3,17 @@ require_relative './base'
module Feature module Feature
class MergeTo < Feature::Base class MergeTo < Feature::Base
def valid?
[1,2].include? argv.size
end
def help
puts
puts "USAGE: feature merge [branch]"
puts
exit
end
def execute def execute
parts = parse_branch(current_branch) parts = parse_branch(current_branch)
@@ -10,8 +21,6 @@ module Feature
merge_to_branch = argv[1] merge_to_branch = argv[1]
elsif argv.size == 1 elsif argv.size == 1
merge_to_branch = parts[:standard] merge_to_branch = parts[:standard]
else
error "USAGE: feature merge [branch]"
end end
feature_branch = current_branch feature_branch = current_branch

View File

@@ -3,6 +3,18 @@ require_relative './base'
module Feature module Feature
class Rebase < Feature::Base class Rebase < Feature::Base
def valid?
argv.size == 1
end
def help
puts
puts "USAGE: feature rebase"
puts
exit
end
def execute def execute
parts = parse_branch(current_branch) parts = parse_branch(current_branch)

View File

@@ -3,9 +3,18 @@ require_relative './base'
module Feature module Feature
class Start < Feature::Base class Start < Feature::Base
def execute def valid?
error "USAGE: feature start feature_name" unless argv.size == 2 argv.size == 2
end
def help
puts
puts "USAGE: feature start feature_name"
puts
exit
end
def execute
feature = argv[1] feature = argv[1]
feature_branch = "#{ENV['USER']}-#{current_branch}-#{feature}" feature_branch = "#{ENV['USER']}-#{current_branch}-#{feature}"