Class: CodeShift::CLI
- Inherits:
-
Object
- Object
- CodeShift::CLI
- Defined in:
- lib/codeshift/cli.rb
Overview
Cli Class
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #process_file(file_path) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/codeshift/cli.rb', line 12 def initialize @options = Codeshift::Options.new OptionParser.new do |opts| opts. = 'Usage: codeshift -t <transform-file> [path]' opts.on('--version', 'Print version number') do puts Codeshift::VERSION exit end opts.on('-tTRANSFORM', '--transform=TRANSFORM', 'path to the transform file. Can be either a local path or url\n (default: ./transform.rb)') do |f| @options.transform = f end opts.on('-h', '--help', 'Prints this help') do puts opts exit end end.parse! @files = ARGV end |
Instance Method Details
#process_file(file_path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/codeshift/cli.rb', line 35 def process_file(file_path) puts "Processing: #{file_path}" code = File.read(file_path) # transform = open(@options.transform, '&:read') response = open(@options.transform) transform = response.read output = Codeshift::Transformer.new(code, transform).transform File.write(file_path, output) end |
#run ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/codeshift/cli.rb', line 45 def run paths = @files.empty? ? [] : @files paths.each do |path| if File.directory?(path) glob_path = File.join(path, '**', '*.rb') Dir.glob(glob_path) do |file_path| process_file file_path end else process_file path end end end |