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

Quality of life requests #360

Merged
merged 7 commits into from
Dec 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
aptible-cli (0.24.0)
aptible-cli (0.24.1)
activesupport (>= 4.0, < 6.0)
aptible-api (~> 1.6.5)
aptible-auth (~> 1.2.5)
Expand Down
16 changes: 11 additions & 5 deletions lib/aptible/cli/helpers/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ def environment_from_handle(handle)

def ensure_default_environment
environments = Aptible::Api::Account.all(token: fetch_token)
return environments.first if environments.count == 1

raise Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
Multiple environments available, please specify with --environment
ERR
case environments.count
when 0
e = 'No environments. Go to https://app.aptible.com/ to proceed'
raise Thor::Error, e
when 1
return environments.first
else
raise Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
Multiple environments available, please specify with --environment or --env
ERR
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/aptible/cli/resource_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def inject_service(node, service, app)
node.value('command', service.command || 'CMD')
node.value('container_count', service.container_count)
node.value('container_size', service.container_memory_limit_mb)
node.value('container_profile', service.instance_class.to_s[/[a-z]/])

attach_app(node, app)
end
Expand Down
14 changes: 8 additions & 6 deletions lib/aptible/cli/subcommands/apps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.included(thor)
include Helpers::Token

desc 'apps', 'List all applications'
option :environment
option :environment, aliases: '--env'
def apps
Formatter.render(Renderer.current) do |root|
root.grouped_keyed_list(
Expand All @@ -28,7 +28,7 @@ def apps
end

desc 'apps:create HANDLE', 'Create a new application'
option :environment
option :environment, aliases: '--env'
define_method 'apps:create' do |handle|
environment = ensure_environment(options)
app = environment.create_app(handle: handle)
Expand Down Expand Up @@ -69,9 +69,11 @@ def apps
raise Thor::Error, m
end

if container_count.nil? && container_size.nil?
raise Thor::Error,
'Provide at least --container-count or --container-size'
if container_count.nil? && container_size.nil? &&
container_profile.nil?
m = 'Provide at least --container-count, --container-size, ' \
'or --container-profile'
raise Thor::Error, m
end

# We don't validate any parameters here: API will do that for us.
Expand Down Expand Up @@ -104,7 +106,7 @@ def apps
' ENVIRONMENT_HANDLE]', 'Rename an app handle. In order'\
' for the new app handle to appear in log drain and metric'\
' drain destinations, you must restart the app.'
option :environment
option :environment, aliases: '--env'
define_method 'apps:rename' do |old_handle, new_handle|
env = ensure_environment(options)
app = ensure_app(options.merge(app: old_handle))
Expand Down
11 changes: 6 additions & 5 deletions lib/aptible/cli/subcommands/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def self.included(thor)
'[--key-arn KEY_ARN]',
'Restore a backup'
option :handle, desc: 'a name to use for the new database'
option :environment, desc: 'a different environment to restore to'
option :environment, aliases: '--env',
desc: 'a different environment to restore to'
option :container_size, type: :numeric
option :size, type: :numeric
option :disk_size, type: :numeric
Expand Down Expand Up @@ -68,9 +69,9 @@ def self.included(thor)
end

desc 'backup:list DB_HANDLE', 'List backups for a database'
option :environment
option :environment, aliases: '--env'
option :max_age,
default: '1mo',
default: '99y',
desc: 'Limit backups returned (example usage: 1w, 1y, etc.)'
define_method 'backup:list' do |handle|
age = ChronicDuration.parse(options[:max_age])
Expand All @@ -95,8 +96,8 @@ def self.included(thor)

desc 'backup:orphaned', 'List backups associated with ' \
'deprovisioned databases'
option :environment
option :max_age, default: '1y',
option :environment, aliases: '--env'
option :max_age, default: '99y',
desc: 'Limit backups returned '\
'(example usage: 1w, 1y, etc.)'
define_method 'backup:orphaned' do
Expand Down
2 changes: 1 addition & 1 deletion lib/aptible/cli/subcommands/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'shellwords'

module Aptible
module CLI
module Subcommands
Expand Down Expand Up @@ -72,6 +71,7 @@ def config
# FIXME: define_method - ?! Seriously, WTF Thor.
app = ensure_app(options)
env = Hash[args.map do |arg|
arg = arg.split('=')[0]
validate_env_key!(arg)
[arg, '']
end]
Expand Down
28 changes: 14 additions & 14 deletions lib/aptible/cli/subcommands/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.included(thor)
include Term::ANSIColor

desc 'db:list', 'List all databases'
option :environment
option :environment, aliases: '--env'
define_method 'db:list' do
Formatter.render(Renderer.current) do |root|
root.grouped_keyed_list(
Expand Down Expand Up @@ -63,7 +63,7 @@ def self.included(thor)
option :disk_size, default: 10, type: :numeric
option :size, type: :numeric
option :key_arn, type: :string
option :environment
option :environment, aliases: '--env'
option :container_profile, type: :string,
desc: 'Examples: m c r'
option :iops, type: :numeric
Expand Down Expand Up @@ -126,7 +126,7 @@ def self.included(thor)
end

desc 'db:clone SOURCE DEST', 'Clone a database to create a new one'
option :environment
option :environment, aliases: '--env'
define_method 'db:clone' do |source_handle, dest_handle|
# TODO: Deprecate + recommend backup
source = ensure_database(options.merge(db: source_handle))
Expand All @@ -139,7 +139,7 @@ def self.included(thor)
'[--container-profile PROFILE] [--iops IOPS] ' \
'[--logical --version VERSION] [--key-arn KEY_ARN]',
'Create a replica/follower of a database'
option :environment
option :environment, aliases: '--env'
option :container_size, type: :numeric
option :size, type: :numeric
option :disk_size, type: :numeric
Expand Down Expand Up @@ -191,7 +191,7 @@ def self.included(thor)

desc 'db:dump HANDLE [pg_dump options]',
'Dump a remote database to file'
option :environment
option :environment, aliases: '--env'
define_method 'db:dump' do |handle, *dump_options|
database = ensure_database(options.merge(db: handle))
with_postgres_tunnel(database) do |url|
Expand All @@ -204,7 +204,7 @@ def self.included(thor)

desc 'db:execute HANDLE SQL_FILE [--on-error-stop]',
'Executes sql against a database'
option :environment
option :environment, aliases: '--env'
option :on_error_stop, type: :boolean
define_method 'db:execute' do |handle, sql_path|
database = ensure_database(options.merge(db: handle))
Expand All @@ -217,7 +217,7 @@ def self.included(thor)
end

desc 'db:tunnel HANDLE', 'Create a local tunnel to a database'
option :environment
option :environment, aliases: '--env'
option :port, type: :numeric
option :type, type: :string
define_method 'db:tunnel' do |handle|
Expand Down Expand Up @@ -262,7 +262,7 @@ def self.included(thor)
end

desc 'db:deprovision HANDLE', 'Deprovision a database'
option :environment
option :environment, aliases: '--env'
define_method 'db:deprovision' do |handle|
database = ensure_database(options.merge(db: handle))
CLI.logger.info "Deprovisioning #{database.handle}..."
Expand All @@ -278,7 +278,7 @@ def self.included(thor)
end

desc 'db:backup HANDLE', 'Backup a database'
option :environment
option :environment, aliases: '--env'
define_method 'db:backup' do |handle|
database = ensure_database(options.merge(db: handle))
CLI.logger.info "Backing up #{database.handle}..."
Expand All @@ -287,7 +287,7 @@ def self.included(thor)
end

desc 'db:reload HANDLE', 'Reload a database'
option :environment
option :environment, aliases: '--env'
define_method 'db:reload' do |handle|
database = ensure_database(options.merge(db: handle))
CLI.logger.info "Reloading #{database.handle}..."
Expand All @@ -300,7 +300,7 @@ def self.included(thor)
'[--container-profile PROFILE] [--iops IOPS] ' \
'[--volume-type [gp2, gp3]]',
'Restart a database'
option :environment
option :environment, aliases: '--env'
option :container_size, type: :numeric
option :container_profile, type: :string,
desc: 'Examples: m c r'
Expand Down Expand Up @@ -335,7 +335,7 @@ def self.included(thor)
desc 'db:modify HANDLE ' \
'[--iops IOPS] [--volume-type [gp2, gp3]]',
'Modify a database disk'
option :environment
option :environment, aliases: '--env'
option :iops, type: :numeric
option :volume_type
define_method 'db:modify' do |handle|
Expand All @@ -354,7 +354,7 @@ def self.included(thor)
end

desc 'db:url HANDLE', 'Display a database URL'
option :environment
option :environment, aliases: '--env'
option :type, type: :string
define_method 'db:url' do |handle|
database = ensure_database(options.merge(db: handle))
Expand All @@ -371,7 +371,7 @@ def self.included(thor)
' ENVIRONMENT_HANDLE]', 'Rename a database handle. In order'\
' for the new database handle to appear in log drain and'\
' metric drain destinations, you must reload the database.'
option :environment
option :environment, aliases: '--env'
define_method 'db:rename' do |old_handle, new_handle|
env = ensure_environment(options)
db = ensure_database(options.merge(db: old_handle))
Expand Down
4 changes: 2 additions & 2 deletions lib/aptible/cli/subcommands/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.included(thor)
include Helpers::Token

desc 'environment:list', 'List all environments'
option :environment
option :environment, aliases: '--env'
define_method 'environment:list' do
Formatter.render(Renderer.current) do |root|
root.keyed_list(
Expand All @@ -25,7 +25,7 @@ def self.included(thor)

desc 'environment:ca_cert',
'Retrieve the CA certificate associated with the environment'
option :environment
option :environment, aliases: '--env'
define_method 'environment:ca_cert' do
Formatter.render(Renderer.current) do |root|
root.grouped_keyed_list(
Expand Down
6 changes: 3 additions & 3 deletions lib/aptible/cli/subcommands/log_drain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def self.drain_options
option :drain_databases, default: true, type: :boolean
option :drain_ephemeral_sessions, default: true, type: :boolean
option :drain_proxies, default: true, type: :boolean
option :environment
option :environment, aliases: '--env'
end

desc 'log_drain:list', 'List all Log Drains'
option :environment
option :environment, aliases: '--env'
define_method 'log_drain:list' do
Formatter.render(Renderer.current) do |root|
root.grouped_keyed_list(
Expand Down Expand Up @@ -137,7 +137,7 @@ def self.drain_options

desc 'log_drain:deprovision HANDLE --environment ENVIRONMENT',
'Deprovisions a log drain'
option :environment
option :environment, aliases: '--env'
define_method 'log_drain:deprovision' do |handle|
account = ensure_environment(options)
drain = ensure_log_drain(account, handle)
Expand Down
4 changes: 2 additions & 2 deletions lib/aptible/cli/subcommands/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.included(thor)
desc 'maintenance:apps',
'List Apps impacted by maintenance schedules where '\
'restarts are required'
option :environment
option :environment, aliases: '--env'
define_method 'maintenance:apps' do
found_maintenance = false
m = maintenance_apps
Expand Down Expand Up @@ -46,7 +46,7 @@ def self.included(thor)
desc 'maintenance:dbs',
'List Databases impacted by maintenance schedules where '\
'restarts are required'
option :environment
option :environment, aliases: '--env'
define_method 'maintenance:dbs' do
found_maintenance = false
m = maintenance_databases
Expand Down
12 changes: 6 additions & 6 deletions lib/aptible/cli/subcommands/metric_drain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.included(thor)
include Helpers::MetricDrain

desc 'metric_drain:list', 'List all Metric Drains'
option :environment
option :environment, aliases: '--env'
define_method 'metric_drain:list' do
Formatter.render(Renderer.current) do |root|
root.grouped_keyed_list(
Expand All @@ -40,7 +40,7 @@ def self.included(thor)
'--db DATABASE_HANDLE --environment ENVIRONMENT',
'Create an InfluxDB Metric Drain'
option :db, type: :string
option :environment
option :environment, aliases: '--env'

define_method 'metric_drain:create:influxdb' do |handle|
account = ensure_environment(options)
Expand All @@ -66,7 +66,7 @@ def self.included(thor)
option :password, type: :string
option :url, type: :string
option :db, type: :string
option :environment
option :environment, aliases: '--env'
define_method 'metric_drain:create:influxdb:custom' do |handle|
account = ensure_environment(options)

Expand Down Expand Up @@ -95,7 +95,7 @@ def self.included(thor)
option :org, type: :string
option :token, type: :string
option :url, type: :string
option :environment
option :environment, aliases: '--env'
define_method 'metric_drain:create:influxdb:customv2' do |handle|
account = ensure_environment(options)

Expand All @@ -121,7 +121,7 @@ def self.included(thor)
'Create a Datadog Metric Drain'
option :api_key, type: :string
option :site, type: :string
option :environment
option :environment, aliases: '--env'
define_method 'metric_drain:create:datadog' do |handle|
account = ensure_environment(options)

Expand Down Expand Up @@ -150,7 +150,7 @@ def self.included(thor)

desc 'metric_drain:deprovision HANDLE --environment ENVIRONMENT',
'Deprovisions a Metric Drain'
option :environment
option :environment, aliases: '--env'
define_method 'metric_drain:deprovision' do |handle|
account = ensure_environment(options)
drain = ensure_metric_drain(account, handle)
Expand Down
2 changes: 1 addition & 1 deletion lib/aptible/cli/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Aptible
module CLI
VERSION = '0.24.0'.freeze
VERSION = '0.24.1'.freeze
end
end
Loading
Loading