class Dotenv::CLI

The CLI is a class responsible of handling all the command line interface logic.

Attributes

argv[R]

Public Class Methods

new(argv = []) click to toggle source
# File lib/dotenv/cli.rb, line 9
def initialize(argv = [])
  @argv = argv.dup
end

Public Instance Methods

run() click to toggle source
# File lib/dotenv/cli.rb, line 13
def run
  filenames = parse_filenames || []
  begin
    Dotenv.load!(*filenames)
  rescue Errno::ENOENT => e
    abort e.message
  else
    exec(*argv) unless argv.empty?
  end
end

Private Instance Methods

parse_filenames() click to toggle source
# File lib/dotenv/cli.rb, line 26
def parse_filenames
  pos = argv.index("-f")
  return nil unless pos
  # drop the -f
  argv.delete_at pos
  # parse one or more comma-separated .env files
  require "csv"
  CSV.parse_line argv.delete_at(pos)
end