added missing line endings (-l) support for windows and solaris

This commit is contained in:
Geoff Williams 2014-07-09 16:11:08 +10:00 committed by Morgan Haskel
parent ee552804c2
commit 41d8273dfe

16
files/concatfragments.rb Executable file → Normal file
View file

@ -45,7 +45,8 @@ settings = {
:test => false, :test => false,
:force => false, :force => false,
:warn => "", :warn => "",
:sortarg => "" :sortarg => "",
:newline => false
} }
OptionParser.new do |opts| OptionParser.new do |opts|
@ -77,6 +78,10 @@ OptionParser.new do |opts|
opts.on("-n", "--sort", "Sort the output numerically rather than the default alpha sort") do opts.on("-n", "--sort", "Sort the output numerically rather than the default alpha sort") do
settings[:sortarg] = "-n" settings[:sortarg] = "-n"
end end
opts.on("-l", "--line", "Append a newline") do
settings[:newline] = true
end
end.parse! end.parse!
# do we have -o? # do we have -o?
@ -119,8 +124,15 @@ end
# find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir # find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir
open('fragments.concat', 'a') do |f| open('fragments.concat', 'a') do |f|
Dir.entries("fragments").sort.each{ |entry| Dir.entries("fragments").sort.each{ |entry|
if File.file?(File.join("fragments", entry)) if File.file?(File.join("fragments", entry))
f << File.read(File.join("fragments", entry)) f << File.read(File.join("fragments", entry))
# append a newline if we were asked to (invoked with -l)
if settings[:newline]
f << "\n"
end
end end
} }
end end