bin/acquia in acquia_toolbelt-1.3.0 vs bin/acquia in acquia_toolbelt-1.4.0

- old
+ new

@@ -123,10 +123,38 @@ true else false end end + + # Internal: Output information on a database instance. + def output_database_instance(database) + say "> Username: #{database["username"]}" + say "> Password: #{database["password"]}" + say "> Host: #{database["host"]}" + say "> DB cluster: #{database["db_cluster"]}" + say "> Instance name: #{database["instance_name"]}" + end + + # Internal: Output information for a single task item. + def output_task_item(task) + completion_time = (task["completed"].to_i - task["started"].to_i) / 60 + say + say "Task ID: #{task["id"].to_i}" + say "Description: #{task["description"]}" + say "Status: #{task["state"]}" + + # If the completion time is greater then 0, output it in minutes otherwise + # just say it was less then a minute. + if completion_time > 0 + say "Compeletion time: About #{completion_time} minutes" + else + say "Compeletion time: Less than 1 minute" + end + + say "Queue: #{task["queue"]}" + end } # Public: Log into the Acquia Cloud API. # # This sets up the user account within the netrc file so that subsequent @@ -271,29 +299,21 @@ # If we have both the database name and environment, only fetch a single # result. if options[:database] && options[:environment] database = acquia_api_call "sites/#{subscription}/envs/#{options[:environment]}/dbs/#{options[:database]}" say - say "> Username: #{database["username"]}" - say "> Password: #{database["password"]}" - say "> Host: #{database["host"]}" - say "> DB cluster: #{database["db_cluster"]}" - say "> Instance name: #{database["instance_name"]}" + output_database_instance(database) return end # Fetch all the databases in a specific environment. if options[:environment] databases = acquia_api_call "sites/#{subscription}/envs/#{options[:environment]}/dbs" databases.each do |db| say say "#{db["name"]}" - say "> Username: #{db["username"]}" - say "> Password: #{db["password"]}" - say "> Host: #{db["host"]}" - say "> DB cluster: #{db["db_cluster"]}" - say "> Instance name: #{db["instance_name"]}" + output_database_instance(db) end else subscription_envs = [options[:environment]] databases = acquia_api_call "sites/#{subscription}/dbs" @@ -488,9 +508,43 @@ # Returns a status message string. desc "deploy-code <subscription> <environment> <release>", "Deploy a specific VCS branch or tag to an environment." def deploy_code(subscription, environment, release) deploy_code = acquia_api_call "sites/#{subscription}/envs/#{environment}/code-deploy", "CODE-DEPLOY-POST", :release => "#{release}" success "#{release} has been deployed to #{environment}." if deploy_code["id"] + end + + # Public: Show tasks for a subscription. + # + # Returns a listing of tasks for a subscription. + desc "list-tasks <subscription>", "Display tasks associated with a subscription." + option :count, :aliases => "-c" + option :queue, :aliases => "-q" + def list_tasks(subscription) + all_tasks = acquia_api_call "sites/#{subscription}/tasks" + tasks = [] + + # Fetch a single queue from the tasks list if the queue parameter is set + # otherwise just add all the tasks. + if options[:queue] + all_tasks.each do |task| + if task["queue"] == options[:queue] + tasks << task + end + end + else + all_tasks.each do |task| + tasks << task + end + end + + # If there is a count to return, restrict it to that required amount. + if options[:count] && tasks.any? + tasks = tasks.last(options[:count].to_i) + end + + tasks.each do |task| + output_task_item(task) + end end end Acquia.start \ No newline at end of file