Method: Fast::Cli#initialize
- Defined in:
- lib/fast/cli.rb
#initialize(args) ⇒ Cli
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fast/cli.rb', line 46 def initialize(args) @opt = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength opts. = 'Usage: fast expression <files> [options]' opts.on('-d', '--debug', 'Debug fast engine') do @debug = true end opts.on('--ast', 'Print AST instead of code') do @show_sexp = true end opts.on('--pry', 'Jump into a pry session with results') do @pry = true end opts.on('-c', '--code', 'Create a pattern from code example') do if @pattern @from_code = true @pattern = Fast.ast(@pattern).to_sexp debug 'Expression from AST:', @pattern end end opts.on('-s', '--similar', 'Search for similar code.') do @similar = true @pattern = Fast.expression_from(Fast.ast(@pattern)) debug "Looking for code similar to #{@pattern}" end opts.on_tail('--version', 'Show version') do puts Fast::VERSION exit end opts.on_tail('-h', '--help', 'Show help. More at https://jonatas.github.io/fast') do @help = true end @pattern, *@files = args.reject { |arg| arg.start_with? '-' } end @opt.parse! args @files = [*@files] @files.reject! { |arg| arg.start_with?('-') } end |