From d9334aa2247b4716167cf34df0bfacf968ae7bde Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 24 Feb 2018 22:28:10 -0500 Subject: [PATCH] add Config class and initial status handler --- lib/svi.rb | 17 +++++++++++++++++ lib/svi/cli.rb | 6 ++++++ lib/svi/config.rb | 35 +++++++++++++++++++++++++++++++++++ lib/svi/util.rb | 15 +++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 lib/svi/config.rb create mode 100644 lib/svi/util.rb diff --git a/lib/svi.rb b/lib/svi.rb index bf8e80c..80d61bc 100644 --- a/lib/svi.rb +++ b/lib/svi.rb @@ -1,6 +1,8 @@ require_relative "svi/ansi" require_relative "svi/cli" +require_relative "svi/config" require_relative "svi/svn_runner" +require_relative "svi/util" require_relative "svi/version" require "svi/svi" @@ -58,5 +60,20 @@ module Svi 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 c2b0334..016e304 100644 --- a/lib/svi/cli.rb +++ b/lib/svi/cli.rb @@ -65,6 +65,12 @@ EOS Svi.checkout(url) end + def cmd_status(params) + options = {} + opts, args = Yawpa.parse(params, options, posix_order: true) + Svi.status + end + end end end diff --git a/lib/svi/config.rb b/lib/svi/config.rb new file mode 100644 index 0000000..4dc565c --- /dev/null +++ b/lib/svi/config.rb @@ -0,0 +1,35 @@ +module Svi + class Config + + def initialize + @ignores = [] + + load_global_config + end + + # Get the ignore patterns. + # + # @return [Array] + # Each entry is a pattern or a Proc that returns a list of patterns. + def ignores + @_ignores ||= @ignores.map do |ignore| + if ignore.is_a?(Proc) + ignore[] + else + ignore + end + end.flatten + end + + private + + def load_global_config + global_config_path = "#{ENV["HOME"]}/.svi/config" + if File.exists?(global_config_path) + global_config = File.read(global_config_path) + instance_eval(global_config, global_config_path, 1) + end + end + + end +end diff --git a/lib/svi/util.rb b/lib/svi/util.rb new file mode 100644 index 0000000..b7c10b4 --- /dev/null +++ b/lib/svi/util.rb @@ -0,0 +1,15 @@ +module Svi + module Util + + class << self + + def is_path_ignored?(path, config) + config.ignores.find do |ignore_pattern| + File.fnmatch(ignore_pattern, path, File::FNM_PATHNAME) + end + end + + end + + end +end