class Dotenv::CLI
The CLI is a class responsible of handling all the command line interface logic.
Attributes
argv[R]
filenames[R]
Public Class Methods
new(argv = [])
click to toggle source
# File lib/dotenv/cli.rb, line 12 def initialize(argv = []) @argv = argv.dup @filenames = [] end
Public Instance Methods
run()
click to toggle source
# File lib/dotenv/cli.rb, line 17 def run parse_argv!(@argv) begin Dotenv.load!(*@filenames) rescue Errno::ENOENT => e abort e.message else exec(*@argv) unless @argv.empty? end end
Private Instance Methods
add_files_option(parser)
click to toggle source
# File lib/dotenv/cli.rb, line 46 def add_files_option(parser) parser.on("-f FILES", Array, "List of env files to parse") do |list| @filenames = list end end
add_help_option(parser)
click to toggle source
# File lib/dotenv/cli.rb, line 52 def add_help_option(parser) parser.on("-h", "--help", "Display help") do puts parser exit end end
add_options(parser)
click to toggle source
# File lib/dotenv/cli.rb, line 39 def add_options(parser) add_files_option(parser) add_help_option(parser) add_version_option(parser) add_template_option(parser) end
add_template_option(parser)
click to toggle source
# File lib/dotenv/cli.rb, line 66 def add_template_option(parser) parser.on("-t", "--template=FILE", "Create a template env file") do |file| template = Dotenv::EnvTemplate.new(file) template.create_template end end
add_version_option(parser)
click to toggle source
# File lib/dotenv/cli.rb, line 59 def add_version_option(parser) parser.on("-v", "--version", "Show version") do puts "dotenv #{Dotenv::VERSION}" exit end end
create_option_parser()
click to toggle source
# File lib/dotenv/cli.rb, line 73 def create_option_parser OptionParser.new do |parser| parser.banner = "Usage: dotenv [options]" parser.separator "" end end
parse_argv!(argv)
click to toggle source
# File lib/dotenv/cli.rb, line 31 def parse_argv!(argv) parser = create_option_parser add_options(parser) parser.order!(argv) @filenames end