class DotEnviOS::CLI

Public Class Methods

new() click to toggle source
# File lib/dotenv-ios/cli.rb, line 17
def initialize
  @options = parse_options

  @ui = DotEnviOS::UI.new(@options.verbose, @options.debug)

  assert_options

  DotEnviOS::Generator.new(@options).start
end

Public Instance Methods

assert_options() click to toggle source
# File lib/dotenv-ios/cli.rb, line 67
def assert_options
  prefix = '[ERROR]'
  @ui.fail("#{prefix} --source required") unless @options.source
end
parse_options() click to toggle source
# File lib/dotenv-ios/cli.rb, line 27
def parse_options
  options = Options.new
  options.verbose = false
  options.debug = false

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: dotenv-ios [options]'

    opts.on('-v', '--version', 'Print version') do
      puts DotEnviOS::Version.get
      exit
    end
    opts.on('-s', '--source DIR', 'Source code directory to check for requested environment variables') do |source|
      options.source = source
      options.out = Pathname.new(source).join('Env.swift') # set default
    end
    opts.on('--verbose', 'Verbose output') do
      options.verbose = true
    end
    opts.on('--debug', 'Debug output (also turns on verbose)') do
      options.verbose = true
      options.debug = true
    end
    opts.on('-o', '--out FILE', 'Output file') do |out|
      options.out = out
    end
    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end
  end

  help = opt_parser.help
  abort(help) if ARGV.empty?

  opt_parser.parse!(ARGV)

  options
end