class GitSu::Gitsu
Public Class Methods
new(switcher, output)
click to toggle source
# File lib/gitsu/gitsu.rb, line 22 def initialize(switcher, output) @switcher, @output = switcher, output end
Public Instance Methods
go(args)
click to toggle source
# File lib/gitsu/gitsu.rb, line 26 def go(args) options = {} optparse = OptionParser.new do |opts| opts.version = GitSu::VERSION opts.banner = <<-BANNER Gitsu Copyright (C) 2013 drrb This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/> for details. Usage: git-su [options] user BANNER opts.on('-t', '--list', 'List the configured users') do options[:list] = true end opts.on('-c', '--clear', 'Clear the current user') do options[:clear] = true end opts.on('-a', '--add USER', 'Add a user in email format (e.g. John Citizen <jcitizen@example.com>)') do |user| options[:add] = user end opts.on('-e', '--edit', 'Open the Gitsu config file in an editor') do options[:edit] = true end options[:scope] = [] opts.on('-l', '--local', 'Change user in local scope') do options[:scope] << :local end opts.on('-g', '--global', 'Change user in global scope') do options[:scope] << :global end opts.on('-s', '--system', 'Change user in system scope') do options[:scope] << :system end opts.on('-h', '--help', 'Show this message') do options[:help] = true @output.puts opts end end optparse.parse! args run(options, args) end
Private Instance Methods
run(options, args)
click to toggle source
# File lib/gitsu/gitsu.rb, line 79 def run(options, args) if options[:help] return end if options[:list] @switcher.list return end if options[:edit] @switcher.edit_config return end scopes = options[:scope] if options[:clear] clear_scopes = scopes.empty? ? [:all] : scopes @switcher.clear *clear_scopes end if options[:add] @switcher.add options[:add] end if args.empty? unless options[:add] || options [:clear] print_scopes = scopes.empty? ? [:all] : scopes @switcher.print_current *print_scopes end else select_scopes = scopes.empty? ? [:default] : scopes select_scopes.each do |scope| @switcher.request(scope, *args) end end end