Skip to content

Commit

Permalink
CL < OptionParser to simplify setup more
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Jul 26, 2022
1 parent 961c535 commit 491bfef
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions lib/dotenv/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,42 @@
require "optparse"

module Dotenv
# The CLI is a class responsible of handling all the command line interface
# logic.
class CLI
# The command line interface
class CLI < OptionParser
attr_reader :argv, :filenames, :overload

def initialize(argv = [])
@argv = argv.dup
@filenames = []
@overload = false

@parser = OptionParser.new do |parser|
parser.banner = "Usage: dotenv [options]"
parser.separator ""
super "Usage: dotenv [options]"
separator ""

parser.on("-f FILES", Array, "List of env files to parse") do |list|
@filenames = list
end
on("-f FILES", Array, "List of env files to parse") do |list|
@filenames = list
end

parser.on("-o", "--overload", "override existing ENV variables") do
@overload = true
end
on("-o", "--overload", "override existing ENV variables") do
@overload = true
end

parser.on("-h", "--help", "Display help") do
puts parser
exit
end
on("-h", "--help", "Display help") do
puts self
exit
end

parser.on("-v", "--version", "Show version") do
puts "dotenv #{Dotenv::VERSION}"
exit
end
on("-v", "--version", "Show version") do
puts "dotenv #{Dotenv::VERSION}"
exit
end

parser.on("-t", "--template=FILE", "Create a template env file") do |file|
template = Dotenv::EnvTemplate.new(file)
template.create_template
end
on("-t", "--template=FILE", "Create a template env file") do |file|
template = Dotenv::EnvTemplate.new(file)
template.create_template
end

@parser.order!(@argv)
order!(@argv)
end

def run
Expand Down

0 comments on commit 491bfef

Please sign in to comment.