Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/dotenvious/cli/envious_file_configuror.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Dotenvious
module CLI
class EnviousFileConfiguror
def run
unless envious_present?
puts "You don't have an .envious file present. Create one now? [y\\n]"
decision = STDIN.gets.strip.downcase
if decision == 'y'
create_blank_envious_file
end
end
end

private

def create_blank_envious_file
File.open('.envious', 'w') do |file|
file.write(configuration_skeletion)
end
end

def configuration_skeletion
<<~CONFIG
### Generated by dotenvious. Edit with care!
Dotenvious::Configuration.new do |config|
config.custom_variables = []
config.optional_variables = []
end
CONFIG
end

def envious_present?
File.exist?('.envious')
end
end
end
end
2 changes: 2 additions & 0 deletions lib/dotenvious/cli/main.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require_relative 'env_file_consolidator'
require_relative 'env_file_sorter'
require_relative 'envious_file_configuror'

module Dotenvious
module CLI
class Main
def run
if ARGV[0].to_s.empty?
EnviousFileConfiguror.new.run
EnvFileConsolidator.new.run
elsif ARGV[0].to_s == '--sort'
EnvFileSorter.new.run
Expand Down
46 changes: 46 additions & 0 deletions spec/dotenvious/cli/envious_file_configuror_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

describe Dotenvious::CLI::EnviousFileConfiguror do
describe '#run' do
context 'when no .envious file exists' do
before do
allow(File).to receive(:exist?).with('.envious').and_return false
end

context 'and the user wants to create an .envious file' do
before do
expect(STDIN).to receive(:gets).and_return "y"
end
it 'creates the file' do
fake_file = double(File)
expect(File).to receive(:open).and_yield fake_file
expect(fake_file).to receive(:write)

described_class.new.run
end
end

context 'but the user does not want to create an .envious file' do
before do
expect(STDIN).to receive(:gets).and_return "n"
end
it 'does nothing' do
expect(File).not_to receive(:open)

described_class.new.run
end
end
end

context 'when an .envious file exists' do
before do
allow(File).to receive(:exist?).with('.envious').and_return true
end
it 'does not prompt or do anything' do
expect(STDIN).not_to receive(:gets)

described_class.new.run
end
end
end
end
1 change: 1 addition & 0 deletions spec/dotenvious/cli/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
context 'with no flags' do
before do
allow(File).to receive(:read).and_return("")
allow(STDIN).to receive(:gets).and_return('n')
end

it 'begins the EnvFileConsolidator' do
Expand Down