add Config class and initial status handler

This commit is contained in:
Josh Holtrop 2018-02-24 22:28:10 -05:00
parent f1ed0cb50f
commit d9334aa224
4 changed files with 73 additions and 0 deletions

View File

@ -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

View File

@ -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

35
lib/svi/config.rb Normal file
View File

@ -0,0 +1,35 @@
module Svi
class Config
def initialize
@ignores = []
load_global_config
end
# Get the ignore patterns.
#
# @return [Array<String, Proc>]
# 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

15
lib/svi/util.rb Normal file
View File

@ -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