Class: Gjallarhorn::CLI
- Inherits:
-
Thor
- Object
- Thor
- Gjallarhorn::CLI
- Defined in:
- lib/gjallarhorn/cli.rb
Overview
Command-line interface for Gjallarhorn deployment operations
The CLI class provides a Thor-based command-line interface for all deployment operations including deploy, status checks, rollbacks, and configuration management. All methods include comprehensive error handling and user-friendly output.
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
Default configuration file path
"config/deploy.yml"
Instance Method Summary collapse
-
#config ⇒ Object
Display the current configuration in YAML format.
-
#deploy(environment, image) ⇒ Object
Deploy a container image to the specified environment.
-
#display_deployment_record(record) ⇒ void
private
Display a single deployment record with formatting.
-
#history(environment) ⇒ Object
Display deployment history for the specified environment.
-
#rollback(environment, version) ⇒ Object
Rollback services in an environment to a previous version.
-
#status(environment) ⇒ Object
Check the deployment status for services in an environment.
-
#version ⇒ Object
Display the current Gjallarhorn version.
Instance Method Details
#config ⇒ Object
Display the current configuration in YAML format
78 79 80 81 82 83 84 |
# File 'lib/gjallarhorn/cli.rb', line 78 def config configuration = Configuration.new([:config]) puts configuration.to_yaml rescue StandardError => e puts "Configuration error: #{e.}" exit 1 end |
#deploy(environment, image) ⇒ Object
Deploy a container image to the specified environment
35 36 37 38 39 40 41 |
# File 'lib/gjallarhorn/cli.rb', line 35 def deploy(environment, image) deployer = Deployer.new([:config]) deployer.deploy(environment, image) rescue StandardError => e puts "Deployment failed: #{e.}" exit 1 end |
#display_deployment_record(record) ⇒ void (private)
This method returns an undefined value.
Display a single deployment record with formatting
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/gjallarhorn/cli.rb', line 130 def display_deployment_record(record) = Time.parse(record["timestamp"]).strftime("%Y-%m-%d %H:%M:%S UTC") status_indicator = case record["status"] when "success" then "✅" when "failed" then "❌" else "🔄" end puts "#{status_indicator} #{} - #{record["image"]}" puts " Status: #{record["status"]}" puts " Strategy: #{record["strategy"]}" if record["strategy"] puts " Error: #{record["error"]}" if record["error"] puts end |
#history(environment) ⇒ Object
Display deployment history for the specified environment
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gjallarhorn/cli.rb', line 92 def history(environment) history_manager = History.new records = history_manager.get_history(environment: environment, limit: [:limit]) if records.empty? puts "No deployment history found for #{environment}" return end puts "Deployment history for #{environment}:" puts "=" * 60 records.each do |record| display_deployment_record(record) end # Show statistics stats = history_manager.statistics(environment: environment) puts "Statistics:" puts " Total deployments: #{stats[:total_deployments]}" puts " Success rate: #{stats[:success_rate]}% (#{stats[:successful_deployments]}/#{stats[:total_deployments]})" rescue StandardError => e puts "Failed to retrieve history: #{e.}" exit 1 end |
#rollback(environment, version) ⇒ Object
Rollback services in an environment to a previous version
67 68 69 70 71 72 73 |
# File 'lib/gjallarhorn/cli.rb', line 67 def rollback(environment, version) deployer = Deployer.new([:config]) deployer.rollback(environment, version) rescue StandardError => e puts "Rollback failed: #{e.}" exit 1 end |
#status(environment) ⇒ Object
Check the deployment status for services in an environment
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gjallarhorn/cli.rb', line 48 def status(environment) deployer = Deployer.new([:config]) result = deployer.status(environment) puts "Status for #{environment}:" result.each do |status_info| puts " #{status_info}" end rescue StandardError => e puts "Status check failed: #{e.}" exit 1 end |
#version ⇒ Object
Display the current Gjallarhorn version
120 121 122 |
# File 'lib/gjallarhorn/cli.rb', line 120 def version puts Gjallarhorn::VERSION end |