adding-help: commit optimized tab completion and help
This commit is contained in:
@@ -1,34 +1,11 @@
|
||||
require_relative './start'
|
||||
require_relative './end'
|
||||
require_relative './trash'
|
||||
require_relative './rebase'
|
||||
require_relative './merge_to'
|
||||
require_relative './tab'
|
||||
require_relative './branch'
|
||||
require_relative './commit'
|
||||
require_relative './help'
|
||||
|
||||
module Feature
|
||||
|
||||
class Commander
|
||||
attr_reader :subcommands, :subcommand
|
||||
attr_reader :subcommand
|
||||
|
||||
def initialize (argv)
|
||||
@subcommands = {
|
||||
branch: Feature::Branch.new(argv),
|
||||
commit: Feature::Commit.new(argv),
|
||||
help: Feature::Help.new(argv),
|
||||
end: Feature::End.new(argv),
|
||||
rebase: Feature::Rebase.new(argv),
|
||||
merge: Feature::MergeTo.new(argv),
|
||||
start: Feature::Start.new(argv),
|
||||
tab: Feature::Tab.new(argv),
|
||||
trash: Feature::Trash.new(argv)
|
||||
}
|
||||
|
||||
key = (argv[0] ? argv[0].to_sym : :branch)
|
||||
|
||||
@subcommand = (subcommands[key] ? subcommands[key] : subcommands[:help])
|
||||
@subcommand = Commander.create(key,argv)
|
||||
end
|
||||
|
||||
def valid?
|
||||
@@ -43,6 +20,30 @@ module Feature
|
||||
subcommand.execute
|
||||
end
|
||||
|
||||
def self.commands
|
||||
[
|
||||
:branch,
|
||||
:commit,
|
||||
:help,
|
||||
:end,
|
||||
:rebase,
|
||||
:merge,
|
||||
:start,
|
||||
:tab,
|
||||
:trash
|
||||
].sort
|
||||
end
|
||||
|
||||
def self.create key, argv
|
||||
key = "help" unless Commander.commands.include? key
|
||||
require_relative "./#{key}"
|
||||
klass = Module.const_get "Feature::#{key.capitalize}"
|
||||
klass.new(argv)
|
||||
end
|
||||
|
||||
def self.create_all argv
|
||||
commands.map { |x| create(x,argv) }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -13,10 +13,7 @@ module Feature
|
||||
|
||||
def execute
|
||||
puts
|
||||
# TODO: fix this
|
||||
commander = Feature::Commander.new(argv)
|
||||
commander.subcommands.keys.sort.each do |key|
|
||||
cmd = commander.subcommands[key]
|
||||
Feature::Commander.create_all(argv).each do |cmd|
|
||||
puts cmd.help
|
||||
end
|
||||
puts
|
||||
|
||||
@@ -2,7 +2,7 @@ require_relative './base'
|
||||
|
||||
module Feature
|
||||
|
||||
class MergeTo < Feature::Base
|
||||
class Merge < Feature::Base
|
||||
def valid?
|
||||
[1,2].include? argv.size
|
||||
end
|
||||
@@ -20,10 +20,7 @@ module Feature
|
||||
|
||||
regexp = Regexp.new(pattern)
|
||||
|
||||
# TODO: fix this
|
||||
cmds = Feature::Commander.new(argv).subcommands.keys.map(&:to_s).sort.select { |x| regexp.match(x) }
|
||||
|
||||
puts cmds.join("\n")
|
||||
puts Feature::Commander.commands.select { |x| regexp.match(x.to_s) }.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user