lib/dotenv/cli.rb in dotenv-2.7.2 vs lib/dotenv/cli.rb in dotenv-2.7.3

- old
+ new

@@ -1,7 +1,8 @@ require "dotenv" require "dotenv/version" +require "dotenv/template" require "optparse" module Dotenv # The CLI is a class responsible of handling all the command line interface # logic. @@ -19,11 +20,11 @@ begin Dotenv.load!(*@filenames) rescue Errno::ENOENT => e abort e.message else - exec(*@argv) unless @argv.empty? + exec(*@argv) if @argv.present? end end private @@ -37,10 +38,11 @@ def add_options(parser) add_files_option(parser) add_help_option(parser) add_version_option(parser) + add_template_option(parser) end def add_files_option(parser) parser.on("-f FILES", Array, "List of env files to parse") do |list| @filenames = list @@ -56,9 +58,16 @@ def add_version_option(parser) parser.on("-v", "--version", "Show version") do puts "dotenv #{Dotenv::VERSION}" exit + end + end + + 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 def create_option_parser OptionParser.new do |parser|