Class: Ronin::DB::CLI::Commands::Add Private
- Inherits:
-
Ronin::DB::CLI::Command
- Object
- Core::CLI::Command
- Ronin::DB::CLI::Command
- Ronin::DB::CLI::Commands::Add
- Includes:
- URIMethods
- Defined in:
- lib/ronin/db/cli/commands/add.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Adds an existing database to the ~/.config/ronin-db/database.yml
configuration file.
Usage
ronin-db add [options] NAME [URI]
Options
-A sqlite3|mysql2|postgresql|...,
--adapter The database adapter
--sqlite3 FILE Alias for --adapter sqlite3 --database FILE
--mysql2 Alias for --adapter mysql2
--postgresql Alias for --adapter postgresql
-H, --host HOST The host of the database to add
-p, --port PORT The port of the database to add
-u, --username USER The user to authenticate with for the database
-P, --password PASSWORD The password to authenticate with for the database
--read-password Reads the database password from stdin
-D, --database NAME|PATH The database name or path (for sqlite3)
-h, --help Print help information
Arguments
NAME The name of the database to add.
[URI] The optional URI to the database.
Constant Summary
Constants included from URIMethods
Instance Attribute Summary collapse
-
#config ⇒ Hash{Symbol => Object}
readonly
private
The database configuration Hash to add.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Add
constructor
private
Initializes the command.
-
#read_password ⇒ Object
private
Reads the password from stdin and sets
config[:password]
. -
#run(name, uri = nil) ⇒ Object
private
Runs the
ronin-db add
command. -
#validate_config! ⇒ Object
private
Validates the #config Hash.
Methods included from URIMethods
#normalize_adapter, #normalize_sqlite3_path, #parse_uri
Constructor Details
#initialize(**kwargs) ⇒ Add
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the command.
160 161 162 163 164 |
# File 'lib/ronin/db/cli/commands/add.rb', line 160 def initialize(**kwargs) super(**kwargs) @config = {} end |
Instance Attribute Details
#config ⇒ Hash{Symbol => Object} (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The database configuration Hash to add.
152 153 154 |
# File 'lib/ronin/db/cli/commands/add.rb', line 152 def config @config end |
Instance Method Details
#read_password ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads the password from stdin and sets config[:password]
.
183 184 185 |
# File 'lib/ronin/db/cli/commands/add.rb', line 183 def read_password @config[:password] = ask_secret('Password') end |
#run(name, uri = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin-db add
command.
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ronin/db/cli/commands/add.rb', line 169 def run(name,uri=nil) @config = parse_uri(uri) if uri read_password if [:read_password] validate_config! ConfigFile.edit do |yaml| yaml[name] = @config end end |
#validate_config! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates the #config Hash.
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ronin/db/cli/commands/add.rb', line 190 def validate_config! unless @config[:adapter] print_error "must specify a URI or the --adapter option" exit(1) end unless @config[:database] print_error "must specify a URI or the --database option" exit(1) end end |