Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add print cli command #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions lib/figaro/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ def install
Install.start
end

# figaro print <environment>

desc "print ENVIRONMENT", "Print the specified environment's variables"

method_option "path",
aliases: ["-p"],
default: "config/application.yml",
desc: "Specify a configuration file path"

define_method "print" do |environment|
require 'figaro/cli/print'
Print.run(options.merge(environment: environment))
end

# figaro heroku:set

desc "heroku:set", "Send Figaro configuration to Heroku"
Expand Down
15 changes: 15 additions & 0 deletions lib/figaro/cli/print.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "figaro/cli/task"

module Figaro
class CLI < Thor
class Print < Task
def run
puts vars
end

def vars
configuration.map{ |k,v| %(#{k}=#{v}) }.join("\n")
end
end
end
end
40 changes: 40 additions & 0 deletions spec/figaro/cli/print_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
describe 'figaro print <environment>' do
before do
create_dir("example")
cd("example")
write_file("config/application.yml", <<-EOF)
foo: bar
production:
foo: baz
test:
bar: boink
EOF
end

it 'respects path' do
write_file("env.yml", "different: path")

cmd = 'figaro print production -p env.yml'
run_simple cmd
expect(output_from(cmd)).to eq("different=path\n")
end

it 'requires the environment to be specified' do
cmd = 'figaro print'
run_simple cmd
expect(output_from(cmd)).to include('figaro print ENVIRONMENT')
end

it 'prints out the production environment' do
cmd = 'figaro print production'
run_simple cmd
expect(output_from(cmd)).to eq("foo=baz\n")
end

it 'prints out the test environment' do
cmd = 'figaro print test'
run_simple cmd

expect(output_from(cmd)).to eq("foo=bar\nbar=boink\n")
end
end