@@ -7,30 +7,37 @@ class Cli
7
7
def parse ( args , env = { } )
8
8
args . shift if args . first == "--" # Handle when called through script/runner
9
9
self . options = Optimist . options ( args ) do
10
- banner "Usage: ruby #{ $PROGRAM_NAME} [options] database [...]\n " \
11
- " ruby #{ $PROGRAM_NAME} [options] -P new_password database [...] to replace all passwords"
10
+ banner "Usage: #{ File . basename ( $PROGRAM_NAME) } [options] database # to migrate from a different or lost key\n " \
11
+ " #{ File . basename ( $PROGRAM_NAME) } -P new_password --databaseyml # to fix database.yml\n " \
12
+ " #{ File . basename ( $PROGRAM_NAME) } --key # to generate a new certs/v2_key "
12
13
13
14
opt :verbose , "Verbose" , :short => "v"
14
15
opt :dry_run , "Dry Run" , :short => "d"
15
16
opt :hostname , "Database Hostname" , :type => :string , :short => "h" , :default => env [ 'PGHOST' ]
16
17
opt :port , "Database Port" , :type => :integer , :default => 5432
17
18
opt :username , "Database Username" , :type => :string , :short => "U" , :default => ( env [ 'PGUSER' ] || "root" )
18
19
opt :password , "Database Password" , :type => :string , :short => "p" , :default => env [ 'PGPASSWORD' ]
19
- opt :hardcode , "Password to use for all passwords" , :type => :string , :short => "P"
20
- opt :invalid , "Password to use for invalid passwords" , :type => :string , :short => "i"
21
- opt :key , "Generate key" , :type => :boolean , :short => "k"
20
+ opt :hardcode , "Password used to replace all passwords" , :type => :string , :short => "P"
21
+ opt :invalid , "Password used to replace non-decryptable passwords" , :type => :string , :short => "i"
22
+ opt :key , "Generate encryption key" , :type => :boolean , :short => "k"
22
23
opt :v2 , "ignored, available for backwards compatibility" , :type => :boolean , :short => "f"
23
24
opt :root , "Rails Root" , :type => :string , :short => "r" ,
24
25
:default => ( env [ 'RAILS_ROOT' ] || File . expand_path ( File . join ( File . dirname ( __FILE__ ) , %w[ .. .. ] ) ) )
25
- opt :databaseyml , "Rewrite database.yml" , :type => :boolean , :short => "y" , :default => false
26
+ opt :databaseyml , "Fix database.yml" , :type => :boolean , :short => "y" , :default => false
26
27
opt :db , "Upgrade database" , :type => :boolean , :short => 'x' , :default => false
27
- opt :legacy_key , "Legacy Key" , :type => :string , :short => "K"
28
+ opt :legacy_key , "Key used to decrypt old passwords when migrating to new key" , :type => :string , :short => "K"
28
29
opt :allow_failures , "Run through all records, even with errors" , :type => :boolean , :short => nil , :default => false
29
30
end
30
31
31
- options [ :database ] = args . first || "vmdb_production"
32
32
# default to updating the db
33
33
options [ :db ] = true if !options [ :key ] && !options [ :databaseyml ]
34
+
35
+ # When converting the database, require database name
36
+ # When RAILS_ENV specified (aka on the appliance) default to production db
37
+ Optimist ::die "please specify a database as an argument" if args . empty? && ENV [ "RAILS_ENV" ] . nil? && options [ :db ]
38
+
39
+ # default to updating
40
+ options [ :database ] = args . first || "vmdb_production"
34
41
self . options = options . delete_if { |_n , v | v . blank? }
35
42
self
36
43
end
0 commit comments