Skip to content

Commit

Permalink
Merge branch 'FI-2832-version-support' of https://github.com/fhir-cru…
Browse files Browse the repository at this point in the history
…cible/fhir_models into FI-2832-version-support
  • Loading branch information
360dgries committed Jul 3, 2024
2 parents 3d5eaed + fc6f642 commit feb59bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AllCops:
- 'spec/**/*'
- 'lib/fhir_models/fhir/**/*'
- 'lib/fhir_models/fhirpath/evaluate.rb'
- 'lib/fhir_models/generated/**/*'
- 'lib/**/*.rake'
- 'tmp/**/*'
- '*.gemspec'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ group :development, :test do
gem 'debug'
gem 'pry'
gem 'pry-byebug'
end
end
24 changes: 12 additions & 12 deletions dir_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: ruby #{__FILE__} [options] dir1 dir2"
opts.on("-n", "--name", "Print files in only one directory") do |n|
opts.on('-n', '--name', 'Print files in only one directory') do |n|
options[:name] = n
end
opts.on("-d", "--diff", "Print filenames with inconsistencies") do |d|
opts.on('-d', '--diff', 'Print filenames with inconsistencies') do |d|
options[:diff] = d
end
opts.on("-v", "--verbose", "Print file inconsistencies") do |v|
opts.on('-v', '--verbose', 'Print file inconsistencies') do |v|
options[:verbose] = v
end
end.parse!

def compare_directories(dir1, dir2, options)
dir1_files = Dir.glob("#{dir1}/**/*").select { |f| File.file?(f) }.map { |f| f.gsub("#{dir1}/", '') }.sort
dir2_files = Dir.glob("#{dir2}/**/*").select { |f| File.file?(f) }.map { |f| f.gsub("#{dir2}/", '') }.sort

# find different files
only_in_dir1 = dir1_files - dir2_files
only_in_dir2 = dir2_files - dir1_files
Expand All @@ -35,18 +35,18 @@ def compare_directories(dir1, dir2, options)
common_files.each do |file|
file1 = File.join(dir1, file)
file2 = File.join(dir2, file)
unless FileUtils.compare_file(file1, file2)
puts "File #{file} differs"
puts Diffy::Diff.new(file1, file2, source: 'files', context: 1) if !options[:verbose].nil?
puts "\n" if !options[:verbose].nil?
end
next if FileUtils.compare_file(file1, file2)

puts "File #{file} differs"
puts Diffy::Diff.new(file1, file2, source: 'files', context: 1) unless options[:verbose].nil?
puts "\n" unless options[:verbose].nil?
end
end

if only_in_dir1.empty? && only_in_dir2.empty? && common_files.all? { |file| FileUtils.compare_file(File.join(dir1, file), File.join(dir2, file)) }
puts "Directories are identical."
puts 'Directories are identical.'
elsif options[:diff].nil?
puts "Directories have unidentical files. Use -d (or --diff) to compare and -v (or --verbose) to see the differences"
puts 'Directories have unidentical files. Use -d (or --diff) to compare and -v (or --verbose) to see the differences'
end
end

Expand All @@ -55,4 +55,4 @@ def compare_directories(dir1, dir2, options)
puts "Usage: ruby #{__FILE__} [options] dir1 dir2"
exit
end
compare_directories(ARGV[0], ARGV[1], options)
compare_directories(ARGV[0], ARGV[1], options)

0 comments on commit feb59bf

Please sign in to comment.