Begin parsing arguments and add checkout command handler
This commit is contained in:
parent
85157bc8f2
commit
50529580c0
@ -4,5 +4,11 @@ require_relative "svi/version"
|
||||
require "svi/svi"
|
||||
|
||||
module Svi
|
||||
# Your code goes here...
|
||||
class << self
|
||||
|
||||
def checkout(url)
|
||||
0
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,70 @@
|
||||
require "yawpa"
|
||||
|
||||
module Svi
|
||||
module Cli
|
||||
class << self
|
||||
def run(args)
|
||||
0
|
||||
|
||||
ALIASES = {
|
||||
"co" => "checkout",
|
||||
}
|
||||
|
||||
HELP_TEXT = <<EOS
|
||||
Usage: svi [options] <command> [parameters...]
|
||||
Global options:
|
||||
--version show svi version and exit
|
||||
--help, -h show this help and exit
|
||||
|
||||
Commands:
|
||||
checkout/co check out Subversion URL
|
||||
EOS
|
||||
|
||||
def run(params)
|
||||
options = {
|
||||
version: {},
|
||||
help: {short: "h"},
|
||||
}
|
||||
opts, args = Yawpa.parse(params, options, posix_order: true)
|
||||
if opts[:version]
|
||||
puts "svi, version #{Svi::VERSION}"
|
||||
return 0
|
||||
end
|
||||
if opts[:help]
|
||||
puts HELP_TEXT
|
||||
return 0
|
||||
end
|
||||
if args.size < 1
|
||||
$stderr.puts HELP_TEXT
|
||||
return 1
|
||||
end
|
||||
run_subcommand(*args)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_subcommand(subcommand, *params)
|
||||
if ALIASES[subcommand]
|
||||
subcommand = ALIASES[subcommand]
|
||||
end
|
||||
command_function = "cmd_#{subcommand}".to_sym
|
||||
if private_methods.include?(command_function)
|
||||
Cli.__send__(command_function, params)
|
||||
else
|
||||
$stderr.puts "Unknown command #{subcommand}"
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
def cmd_checkout(params)
|
||||
options = {}
|
||||
opts, args = Yawpa.parse(params, options, posix_order: true)
|
||||
if args.size < 1
|
||||
$stderr.puts "Error: must specify URL"
|
||||
return 1
|
||||
end
|
||||
url, = args
|
||||
Svi.checkout(url)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user