Class: RoutesApiSpecGenerator::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/routes_api_spec_generator/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(argv = ARGV) ⇒ Object



7
8
9
# File 'lib/routes_api_spec_generator/cli.rb', line 7

def self.start(argv = ARGV)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/routes_api_spec_generator/cli.rb', line 11

def run(argv)
  options = {
    force: false,
    dry_run: false,
    namespace: '/api/v1'
  }

  parser = OptionParser.new do |opts|
    opts.banner = 'Usage: routes-api-spec-generator generate [options]'

    opts.on('--root PATH', 'Rails app root (default: Dir.pwd)') { |v| options[:root] = v }
    opts.on('--force', 'Overwrite existing spec files') { options[:force] = true }
    opts.on('--dry-run', 'Print paths without writing files') { options[:dry_run] = true }
    opts.on('--namespace PATH', 'Route prefix (default: /api/v1)') { |v| options[:namespace] = v }
    opts.on('-h', '--help', 'Show help') { puts opts; exit }
  end

  parser.parse!(argv)
  command = argv.first || 'generate'

  case command
  when 'generate'
    generate!(options)
  else
    warn "Unknown command: #{command}"
    puts parser
    exit 1
  end
end