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
|
module Feature
|
||||||
|
|
||||||
class Commander
|
class Commander
|
||||||
attr_reader :subcommands, :subcommand
|
attr_reader :subcommand
|
||||||
|
|
||||||
def initialize (argv)
|
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)
|
key = (argv[0] ? argv[0].to_sym : :branch)
|
||||||
|
@subcommand = Commander.create(key,argv)
|
||||||
@subcommand = (subcommands[key] ? subcommands[key] : subcommands[:help])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
@@ -43,6 +20,30 @@ module Feature
|
|||||||
subcommand.execute
|
subcommand.execute
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ module Feature
|
|||||||
|
|
||||||
def execute
|
def execute
|
||||||
puts
|
puts
|
||||||
# TODO: fix this
|
Feature::Commander.create_all(argv).each do |cmd|
|
||||||
commander = Feature::Commander.new(argv)
|
|
||||||
commander.subcommands.keys.sort.each do |key|
|
|
||||||
cmd = commander.subcommands[key]
|
|
||||||
puts cmd.help
|
puts cmd.help
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require_relative './base'
|
|||||||
|
|
||||||
module Feature
|
module Feature
|
||||||
|
|
||||||
class MergeTo < Feature::Base
|
class Merge < Feature::Base
|
||||||
def valid?
|
def valid?
|
||||||
[1,2].include? argv.size
|
[1,2].include? argv.size
|
||||||
end
|
end
|
||||||
@@ -20,10 +20,7 @@ module Feature
|
|||||||
|
|
||||||
regexp = Regexp.new(pattern)
|
regexp = Regexp.new(pattern)
|
||||||
|
|
||||||
# TODO: fix this
|
puts Feature::Commander.commands.select { |x| regexp.match(x.to_s) }.join("\n")
|
||||||
cmds = Feature::Commander.new(argv).subcommands.keys.map(&:to_s).sort.select { |x| regexp.match(x) }
|
|
||||||
|
|
||||||
puts cmds.join("\n")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user