class Dotenv::Init::CLI

Public Class Methods

default_value(value) click to toggle source
# File lib/dotenv/init/cli.rb, line 35
def default_value(value)
  try_color("(#{value[:default]}) ", :green) unless value[:default].empty?
end
parsed() click to toggle source
# File lib/dotenv/init/cli.rb, line 31
def parsed
  @parsed ||= CommentAwareParser.call(@contents)
end
prompt(key, value) click to toggle source
# File lib/dotenv/init/cli.rb, line 24
        def prompt(key, value)
          <<~PROMPT.chomp
            #{value[:comments]}
            #{try_color(key, :yellow)}: #{default_value(value)}
          PROMPT
        end
start() click to toggle source
# File lib/dotenv/init/cli.rb, line 7
def start
  @file = File.open(".env.example")
  @contents = @file.read

  env = {}

  parsed.each do |key, value|
    print prompt(key, value)

    value = $stdin.gets.chomp
    env[key] = value.empty? ? nil : value
    puts
  end

  File.write(".env", Assigner.call(@contents, env))
end
try_color(string, color) click to toggle source
# File lib/dotenv/init/cli.rb, line 39
def try_color(string, color)
  require "colorize"
  string.colorize(color)
rescue LoadError
  string
end