class Dotenvious::CLI::Main

Attributes

file_options[R]
options[RW]

Public Class Methods

new() click to toggle source
# File lib/dotenvious/cli/main.rb, line 8
def initialize
  @options = {}
end

Public Instance Methods

run() click to toggle source
# File lib/dotenvious/cli/main.rb, line 12
def run
  parse_options
  EnvFileConsolidator.new(file_options).run
  EnvFileSorter.new(options[:env_file]).run if options[:sort]
end

Private Instance Methods

parse_options() click to toggle source
# File lib/dotenvious/cli/main.rb, line 30
def parse_options
  parser = OptionParser.new do |opts|
    opts.banner = "How to use Dotenvious:"

    opts.on('-x .example-env-file', '--example .example-env-file', 'Specify which example file to use') do |file|
      options[:example_file] = file
    end

    opts.on('-f .env-file', '--file .env-file', 'Specify which file to write to') do |file|
      options[:env_file] = file
    end

    opts.on('-s', '--sort', 'Sort env file by key names alphabetically') do
      options[:sort] = true
    end

    opts.on('-h', '--help', 'View this message') do
      puts opts
      exit
    end
  end

  begin
    parser.parse!
  rescue OptionParser::InvalidOption => e
    puts "Warning #{e}"
  end
end