class Rgit::Cli
Constants
- SUB_COMMANDS
Public Class Methods
new(rgit)
click to toggle source
# File lib/rgit/cli.rb, line 9 def initialize(rgit) @rgit = rgit end
Public Instance Methods
parse(args)
click to toggle source
# File lib/rgit/cli.rb, line 13 def parse(args) parser = rgit_argument_parser global_opts = get_global_options(parser, args) @rgit.verbose = global_opts[:verbose] cmd = args.shift case cmd when 'add-root' add_root(args) when 'remove-root' remove_root(args) when 'checkout' checkout(args) when 'show-roots' show_roots(args) when 'pull' pull(args) when 'fetch' fetch(args) when 'status' status(args) when 'version' puts "rgit #{VERSION}" else puts I18n.t('rgit.unknown_subcommand', command: cmd).red end end
Private Instance Methods
add_root(args)
click to toggle source
# File lib/rgit/cli.rb, line 65 def add_root(args) register_options_banner(args, I18n.t('add_root.banner')) path = args.size == 1 ? args[0] : Dir.pwd @rgit.add_root(path) end
checkout(args)
click to toggle source
# File lib/rgit/cli.rb, line 77 def checkout(args) register_options_banner(args, I18n.t('checkout.banner')) branch = args[0] if args.size == 1 unless branch puts I18n.t('branch.expect_name').red return end @rgit.checkout branch end
fetch(args)
click to toggle source
# File lib/rgit/cli.rb, line 97 def fetch(args) register_options_banner(args, I18n.t('fetch.banner')) @rgit.fetch end
get_global_options(parser, args)
click to toggle source
# File lib/rgit/cli.rb, line 52 def get_global_options(parser, args) Trollop.with_standard_exception_handling parser do raise Trollop::HelpNeeded if args.empty? parser.parse args end end
pull(args)
click to toggle source
# File lib/rgit/cli.rb, line 92 def pull(args) register_options_banner(args, I18n.t('pull.banner')) @rgit.pull end
remove_root(args)
click to toggle source
# File lib/rgit/cli.rb, line 71 def remove_root(args) register_options_banner(args, I18n.t('remove_root.banner')) path = args.size == 1 ? args[0] : Dir.pwd @rgit.remove_root(path) end
rgit_argument_parser()
click to toggle source
# File lib/rgit/cli.rb, line 44 def rgit_argument_parser Trollop::Parser.new do banner I18n.t('rgit.banner') opt :verbose, I18n.t('rgit.run_verbosely'), short: '-v' stop_on SUB_COMMANDS end end
show_roots(args)
click to toggle source
# File lib/rgit/cli.rb, line 87 def show_roots(args) register_options_banner(args, I18n.t('show_roots.banner')) @rgit.print_roots end
status(args)
click to toggle source
# File lib/rgit/cli.rb, line 102 def status(args) register_options_banner(args, I18n.t('status.banner')) @rgit.status end