Sha256: ac2fb5c1d71d5414aaac38a7a3f35e16f8e401c34fb76fc807933ac90cedb1f1
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
require "dotenv" require "dotenv/version" require "optparse" module Dotenv # The CLI is a class responsible of handling all the command line interface # logic. class CLI attr_reader :argv def initialize(argv = []) @argv = argv.dup end 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 def parse_argv!(argv) @filenames = [] OptionParser.new do |parser| parser.banner = "Usage: dotenv [options]" parser.separator "" add_options(parser) end.parse!(argv) @filenames end def add_options(parser) add_files_option(parser) add_help_option(parser) add_version_option(parser) end def add_files_option(parser) parser.on("-f FILES", Array, "List of env files to parse") do |list| @filenames = list end end def add_help_option(parser) parser.on("-h", "--help", "Display help") do puts parser exit end end def add_version_option(parser) parser.on("-v", "--version", "Show version") do puts "dotenv #{Dotenv::VERSION}" exit end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
files.com-1.0.55 | docs/vendor/bundle/ruby/2.5.0/gems/dotenv-2.7.0/lib/dotenv/cli.rb |
dotenv-2.7.0 | lib/dotenv/cli.rb |