Class: DotEnvAndroid::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/dotenv-android/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



17
18
19
20
21
22
23
24
25
# File 'lib/dotenv-android/cli.rb', line 17

def initialize
  @options = parse_options

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

  assert_options

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

Instance Method Details

#assert_optionsObject



67
68
69
70
# File 'lib/dotenv-android/cli.rb', line 67

def assert_options
  prefix = '[ERROR]'
  @ui.fail("#{prefix} --source required") unless @options.source
end

#parse_optionsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dotenv-android/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-android [options]'

    opts.on('-v', '--version', 'Print version') do
      puts DotEnvAndroid::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.kt') # 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 (example: Path/Env.kt)') 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