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

adds cli subcommand for dumping configs in application.yml to STDOUT #240

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
20 changes: 20 additions & 0 deletions lib/figaro/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ def install
Install.start
end

# figaro configs:dump

desc "configs:dump", "Dump configs to STDOUT in an exportable format"
method_option "app_name",
aliases: ["-a"],
desc: "Specify a Dokku app name"
method_option "dokku_alias",
aliases: ["-z"],
desc: "Specify an alias you use to run the dokku/ paas command"
method_option "path",
aliases: ["-p"],
default: "config/application.yml",
desc: "Specify a configuration file path"

define_method "configs:dump" do
require "figaro/cli/configs_dump"
ConfigsDump.run(options)
end


# figaro heroku:set

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

module Figaro
class CLI < Thor
class ConfigsDump < Task
def run
puts command
end

private

def command
# system(configuration, "printf \"#{app_name} #{vars}\"")
# "printf \"config:set save_kittens #{vars} #{for_app} #{for_remote}\n\""

env_vars = configuration.map { |k,v| "#{k.to_s}=\"#{v.to_s.gsub(" ", "\\ ")}\"" unless v.nil? }.join(" ")
"#{dokku_alias} #{app_name} #{env_vars}"
end

def app_name
options[:app_name] ? "config:set #{options[:app_name]}" : nil
end

def dokku_alias
options[:dokku_alias] ? "#{options[:dokku_alias]}" : nil
end

def vars
configuration.keys.map { |k| var(k) }.join(" ")
end

def var(key)
Gem.win_platform? ? %(#{key}="%#{key}%") : %(#{key}="$#{key}")
end
end
end
end