106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/isort.rb', line 106
def self.start
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: sort [options]"
opts.on("-fFILE", "--file=FILE", "File to sort") do |file|
options[:file] = file
end
opts.on("-dDIRECTORY", "--directory=DIRECTORY", "Specify a directory to sort") do |dir|
options[:directory] = dir
end
end.parse!
if options[:file]
sorter = FileSorter.new(options[:file])
sorter.sort_and_format_imports
puts "Imports sorted in #{options[:file]}"
elsif options[:directory]
count = 0
Dir.glob("#{options[:directory]}/**/*.rb").each do |file|
count += 1
sorter = FileSorter.new(file)
sorter.sort_and_format_imports
end
puts "Sorted imports in #{count} files in directory: #{options[:directory]}"
else
puts "Please specify a file using -f or --file"
end
end
|