diff --git a/bin/changit b/bin/changit index 3a486ba..9b57467 100755 --- a/bin/changit +++ b/bin/changit @@ -2,5 +2,4 @@ require 'changit' -options = Changit::CLI.new -Changit.run(options[:src_path], options[:target_paths]) +Changit.run diff --git a/lib/changit.rb b/lib/changit.rb index 4f7a4af..72c03d9 100644 --- a/lib/changit.rb +++ b/lib/changit.rb @@ -9,12 +9,15 @@ require 'changit/cli' module Changit - def self.run(src_file, target_files) + def self.run + # Initialize the CLI and fetch the parameters + options = Changit::CLI.new.options + # File to copy from - config = ConfigReader.new(search_path: src_file).read + config = ConfigReader.new(search_path: options[:src_path]).read # First, search directories inside the current pwd and make sure they contain a .git dir - files_to_write_to = GitDirFinder.new(search_paths: target_files).find_all + files_to_write_to = GitDirFinder.new(search_paths: options[:target_paths]).find_all # Then, copy the gitconfig file content to each .git/config file in these directories ConfigWriter.new(config, files_to_write_to).write diff --git a/lib/changit/cli.rb b/lib/changit/cli.rb index 5c91ddc..8cfa908 100644 --- a/lib/changit/cli.rb +++ b/lib/changit/cli.rb @@ -2,9 +2,11 @@ module Changit class CLI + attr_reader :options + def initialize - options = {} - options[:target_paths] = [] + @options = {} + @options[:target_paths] = [] opt_parser = OptionParser.new do |opt| opt.banner = "Usage: changit [OPTIONS]" @@ -12,13 +14,13 @@ def initialize opt.separator "Options" opt.on("-s","--source SOURCE","Which gitconfig file to copy from") do |src_path| - options[:src_path] = src_path + @options[:src_path] = src_path end opt.on("-t","--target TARGET","Which directory to copy the config to."\ " To copy to different directories, pass more than one -t argument each for one directory" ) do |target_path| - options[:target_paths] << target_path + @options[:target_paths] << target_path end opt.on("-v","--version","Show version number") do @@ -34,9 +36,7 @@ def initialize opt_parser.parse! - options[:target_paths] = nil if options[:target_paths].empty? - options + @options[:target_paths] = nil if @options[:target_paths].empty? end end end -