Skip to content

Commit a8a220a

Browse files
committed
Add print cli command
1 parent 5720b12 commit a8a220a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

lib/figaro/cli.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ def install
1616
Install.start
1717
end
1818

19+
# figaro print <environment>
20+
21+
desc "print ENVIRONMENT", "Print the specified environment's variables"
22+
23+
method_option "path",
24+
aliases: ["-p"],
25+
default: "config/application.yml",
26+
desc: "Specify a configuration file path"
27+
28+
define_method "print" do |environment|
29+
require 'figaro/cli/print'
30+
Print.run(options.merge(environment: environment))
31+
end
32+
1933
# figaro heroku:set
2034

2135
desc "heroku:set", "Send Figaro configuration to Heroku"

lib/figaro/cli/print.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require "figaro/cli/task"
2+
3+
module Figaro
4+
class CLI < Thor
5+
class Print < Task
6+
def run
7+
puts vars
8+
end
9+
10+
def vars
11+
configuration.map{ |k,v| %(#{k}=#{v}) }.join("\n")
12+
end
13+
end
14+
end
15+
end

spec/figaro/cli/print_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
describe 'figaro print <environment>' do
2+
before do
3+
create_dir("example")
4+
cd("example")
5+
write_file("config/application.yml", <<-EOF)
6+
foo: bar
7+
production:
8+
foo: baz
9+
test:
10+
bar: boink
11+
EOF
12+
end
13+
14+
it 'respects path' do
15+
write_file("env.yml", "different: path")
16+
17+
cmd = 'figaro print -p env.yml production'
18+
run_simple cmd
19+
expect(output_from(cmd)).to eq("different=path\n")
20+
end
21+
22+
it 'requires the environment to be specified' do
23+
cmd = 'figaro print'
24+
run_simple cmd
25+
expect(output_from(cmd)).to include('ERROR: "figaro print" was called with no arguments')
26+
end
27+
28+
it 'prints out the production environment' do
29+
cmd = 'figaro print production'
30+
run_simple cmd
31+
expect(output_from(cmd)).to eq("foo=baz\n")
32+
end
33+
34+
it 'prints out the test environment' do
35+
cmd = 'figaro print test'
36+
run_simple cmd
37+
38+
expect(output_from(cmd)).to eq("foo=bar\nbar=boink\n")
39+
end
40+
end

0 commit comments

Comments
 (0)