diff --git a/lib/feature/base.rb b/lib/feature/base.rb index 12f2640..efc4762 100644 --- a/lib/feature/base.rb +++ b/lib/feature/base.rb @@ -13,6 +13,15 @@ module Feature def initialize (argv) @argv = argv end + + def valid? + true + end + + def help + exit + end + end end diff --git a/lib/feature/commander.rb b/lib/feature/commander.rb index 89af5b1..8c23f18 100644 --- a/lib/feature/commander.rb +++ b/lib/feature/commander.rb @@ -7,31 +7,29 @@ require_relative './branch' module Feature class Commander - attr_reader :argv + attr_reader :subcommand 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 def valid? - true + subcommand.valid? end def help - exit + subcommand.help end def execute - command = 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 - command.execute + subcommand.execute end - end end diff --git a/lib/feature/end.rb b/lib/feature/end.rb index f4199bf..5d1736c 100644 --- a/lib/feature/end.rb +++ b/lib/feature/end.rb @@ -3,9 +3,18 @@ require_relative './base' module Feature class End < Feature::Base - def execute - error "USAGE: feature end" unless argv.size == 1 + def valid? + argv.size == 1 + end + def help + puts + puts "USAGE: feature end" + puts + exit + end + + def execute parts = parse_branch(current_branch) standard_branch = parts[:standard] diff --git a/lib/feature/merge_to.rb b/lib/feature/merge_to.rb index 5e5ad17..3a0b647 100644 --- a/lib/feature/merge_to.rb +++ b/lib/feature/merge_to.rb @@ -3,6 +3,17 @@ require_relative './base' module Feature 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 parts = parse_branch(current_branch) @@ -10,8 +21,6 @@ module Feature merge_to_branch = argv[1] elsif argv.size == 1 merge_to_branch = parts[:standard] - else - error "USAGE: feature merge [branch]" end feature_branch = current_branch diff --git a/lib/feature/rebase.rb b/lib/feature/rebase.rb index 53e640d..d042d10 100644 --- a/lib/feature/rebase.rb +++ b/lib/feature/rebase.rb @@ -3,6 +3,18 @@ require_relative './base' module Feature class Rebase < Feature::Base + + def valid? + argv.size == 1 + end + + def help + puts + puts "USAGE: feature rebase" + puts + exit + end + def execute parts = parse_branch(current_branch) diff --git a/lib/feature/start.rb b/lib/feature/start.rb index 7d38271..52d602d 100644 --- a/lib/feature/start.rb +++ b/lib/feature/start.rb @@ -3,9 +3,18 @@ require_relative './base' module Feature class Start < Feature::Base - def execute - error "USAGE: feature start feature_name" unless argv.size == 2 + def valid? + argv.size == 2 + end + def help + puts + puts "USAGE: feature start feature_name" + puts + exit + end + + def execute feature = argv[1] feature_branch = "#{ENV['USER']}-#{current_branch}-#{feature}"