diff --git a/exe/svi b/exe/svi index 9d81fb2..8030bf4 100755 --- a/exe/svi +++ b/exe/svi @@ -4,4 +4,6 @@ require "svi" args = ARGV.dup -exit(Svi::Cli.run(args)) +cli = Svi::Cli.new + +exit(cli.run(args)) diff --git a/lib/svi/cli.rb b/lib/svi/cli.rb index 016e304..d0364f4 100644 --- a/lib/svi/cli.rb +++ b/lib/svi/cli.rb @@ -1,76 +1,74 @@ require "yawpa" module Svi - module Cli - class << self + class Cli - ALIASES = { - "co" => "checkout", - } + ALIASES = { + "co" => "checkout", + } - HELP_TEXT = < [parameters...] - Global options: - --version show svi version and exit - --help, -h show this help and exit +Global options: + --version show svi version and exit + --help, -h show this help and exit - Commands: - checkout/co check out Subversion URL +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) + 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 - - 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 + if opts[:help] + puts HELP_TEXT + return 0 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) + if args.size < 1 + $stderr.puts HELP_TEXT + return 1 end - - def cmd_status(params) - options = {} - opts, args = Yawpa.parse(params, options, posix_order: true) - Svi.status - 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) + __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 + + def cmd_status(params) + options = {} + opts, args = Yawpa.parse(params, options, posix_order: true) + Svi.status + end + end end