lib/dctl/main.rb in dctl_rb-0.12.0 vs lib/dctl/main.rb in dctl_rb-0.13.0
- old
+ new
@@ -1,12 +1,12 @@
module Dctl
class Main
attr_reader :env, :settings
- def initialize(env: "dev")
+ def initialize(env: "dev", config: nil)
@env = env
- load_config!
+ load_config!(config)
end
##
# Generate the full tag for the given image, concatenating the org,
# project, env, image name, and version.
@@ -49,11 +49,11 @@
images.each { |image| check_image(image) }
images
end
- def release(image)
+ def bump(image)
check_image(image)
parsed = parsed_compose_file
service = parsed.dig "services", image
old_tag = service["image"]
@@ -148,10 +148,22 @@
def parsed_compose_file
@parsed_compose_file ||= YAML.load_file compose_file_path
end
##
+ # If there are user defined commands in .dctl.yml, dynamically add them to
+ # the passed thor CLI so they may be executed.
+ def define_custom_commands(klass)
+ Array(settings.custom_commands).each do |command, args|
+ klass.send(:desc, command, "[Custom Command] #{command}")
+ klass.send(:define_method, command, -> do
+ Array(args).each { |a| stream_output(a) }
+ end)
+ end
+ end
+
+ ##
# Ensure the current project's .dctl.yml contains all the requisite keys.
def check_settings!
required_keys = %w(
org
project
@@ -169,11 +181,11 @@
end
##
# Load the current project's config file, complaining if it does not exist
# or is malformed.
- def load_config!
- Config.load_and_set_settings(config_path)
+ def load_config!(custom_config_path = nil)
+ Config.load_and_set_settings(custom_config_path || config_path)
check_settings!
@settings = Settings
end