From 090daf39a09e424e54cfdf2184e345a230dff974 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 27 Feb 2018 20:18:06 -0500 Subject: [PATCH] Add Application class --- lib/svi.rb | 73 +----------------------------------------- lib/svi/application.rb | 71 ++++++++++++++++++++++++++++++++++++++++ lib/svi/cli.rb | 8 +++-- 3 files changed, 78 insertions(+), 74 deletions(-) create mode 100644 lib/svi/application.rb diff --git a/lib/svi.rb b/lib/svi.rb index 80d61bc..4dc4646 100644 --- a/lib/svi.rb +++ b/lib/svi.rb @@ -1,79 +1,8 @@ require_relative "svi/ansi" +require_relative "svi/application" require_relative "svi/cli" require_relative "svi/config" require_relative "svi/svn_runner" require_relative "svi/util" require_relative "svi/version" require "svi/svi" - -module Svi - class << self - - def checkout(url) - checkout_directory = [] - if url =~ %r{/([^/]+)/trunk$} - checkout_directory << $1 - end - last_checkout_message = "" - checked_out_paths = [] - clear_message = lambda do - if last_checkout_message.size > 0 - clear = "" - lines = (last_checkout_message.size + C.screen_width - 1) / C.screen_width - if lines > 1 - clear += Ansi.cursor_up(lines - 1) - end - clear += Ansi.cursor_back(999) - clear += Ansi.erase_cursor_to_eos - $stdout.write(clear) - last_checkout_message = "" - end - end - SvnRunner.run_svn("checkout", [url] + checkout_directory, allow_interactive: true) do |line| - if line =~ /^A.{4}(.*)$/ - path = $1 - checked_out_paths << path - clear_message[] - last_checkout_message = "Checking out #{path}..." - $stdout.write(last_checkout_message) - $stdout.flush - elsif line =~ /^\sU\s{3}/ - # Ignore the 'U'pdate line of the checkout directory itself. - elsif line =~ /^Checked out revision (\d+)/ - revision = $1 - clear_message[] - n_files = 0 - n_directories = 0 - checked_out_paths.uniq.each do |path| - if File.directory?(path) - n_directories += 1 - else - n_files += 1 - end - end - $stdout.puts "Checked out revision #{revision}: #{n_files} file#{n_files == 1 ? '' : 's'}, #{n_directories} director#{n_directories == 1 ? 'y' : 'ies'}" - else - clear_message[] - $stdout.puts line - end - end - 0 - end - - def status - config = Config.new - SvnRunner.run_svn("status", []) do |line| - if line =~ %r{^([ACDIMRX\?!~ ])[CM ][L ][\+ ][SX ][KOTB ]..(.+)$} - action, path = $1, $2 - if action == "?" and Util.is_path_ignored?(path, config) - # Path is ignored - else - puts line - end - end - end - 0 - end - - end -end diff --git a/lib/svi/application.rb b/lib/svi/application.rb new file mode 100644 index 0000000..83af089 --- /dev/null +++ b/lib/svi/application.rb @@ -0,0 +1,71 @@ +module Svi + class Application + + def checkout(url) + checkout_directory = [] + if url =~ %r{/([^/]+)/trunk$} + checkout_directory << $1 + end + last_checkout_message = "" + checked_out_paths = [] + clear_message = lambda do + if last_checkout_message.size > 0 + clear = "" + lines = (last_checkout_message.size + C.screen_width - 1) / C.screen_width + if lines > 1 + clear += Ansi.cursor_up(lines - 1) + end + clear += Ansi.cursor_back(999) + clear += Ansi.erase_cursor_to_eos + $stdout.write(clear) + last_checkout_message = "" + end + end + SvnRunner.run_svn("checkout", [url] + checkout_directory, allow_interactive: true) do |line| + if line =~ /^A.{4}(.*)$/ + path = $1 + checked_out_paths << path + clear_message[] + last_checkout_message = "Checking out #{path}..." + $stdout.write(last_checkout_message) + $stdout.flush + elsif line =~ /^\sU\s{3}/ + # Ignore the 'U'pdate line of the checkout directory itself. + elsif line =~ /^Checked out revision (\d+)/ + revision = $1 + clear_message[] + n_files = 0 + n_directories = 0 + checked_out_paths.uniq.each do |path| + if File.directory?(path) + n_directories += 1 + else + n_files += 1 + end + end + $stdout.puts "Checked out revision #{revision}: #{n_files} file#{n_files == 1 ? '' : 's'}, #{n_directories} director#{n_directories == 1 ? 'y' : 'ies'}" + else + clear_message[] + $stdout.puts line + end + end + 0 + end + + def status + config = Config.new + SvnRunner.run_svn("status", []) do |line| + if line =~ %r{^([ACDIMRX\?!~ ])[CM ][L ][\+ ][SX ][KOTB ]..(.+)$} + action, path = $1, $2 + if action == "?" and Util.is_path_ignored?(path, config) + # Path is ignored + else + puts line + end + end + end + 0 + end + + end +end diff --git a/lib/svi/cli.rb b/lib/svi/cli.rb index d0364f4..f8137c5 100644 --- a/lib/svi/cli.rb +++ b/lib/svi/cli.rb @@ -17,6 +17,10 @@ Commands: checkout/co check out Subversion URL EOS + def initialize + @application = Application.new + end + def run(params) options = { version: {}, @@ -61,13 +65,13 @@ EOS return 1 end url, = args - Svi.checkout(url) + @application.checkout(url) end def cmd_status(params) options = {} opts, args = Yawpa.parse(params, options, posix_order: true) - Svi.status + @application.status end end