Skip to content

Commit

Permalink
Move the CLI initialization into Changit.run
Browse files Browse the repository at this point in the history
  • Loading branch information
aonemd committed Dec 4, 2016
1 parent b1cb8dc commit df49496
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions bin/changit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

require 'changit'

options = Changit::CLI.new
Changit.run(options[:src_path], options[:target_paths])
Changit.run
9 changes: 6 additions & 3 deletions lib/changit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/changit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

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]"
opt.separator ""
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
Expand All @@ -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

0 comments on commit df49496

Please sign in to comment.