Class: Cyoi::Cli::Provider
- Inherits:
-
Object
- Object
- Cyoi::Cli::Provider
- Includes:
- Helpers
- Defined in:
- lib/cyoi/cli/provider.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Provider
constructor
A new instance of Provider.
-
#provider_cli ⇒ Object
Continue the interactive session with the user specific to the provider/infrastructure they have chosen.
Methods included from Helpers::Settings
#migrate_old_settings, #reload_settings!, #save_settings!, #settings, #settings_dir, #settings_path, #settings_ssh_dir, #show_settings
Methods included from Helpers::Provider
#fog_compute, #provider_client
Methods included from Helpers::Interactions
#bold, #clear, #cyan, #green, #hl, #red, #yellow
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Provider
Returns a new instance of Provider.
7 8 9 10 11 |
# File 'lib/cyoi/cli/provider.rb', line 7 def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel @settings_dir = @argv.shift || "/tmp/provider_settings" @settings_dir = File.(@settings_dir) end |
Class Method Details
.provider_cli(name) ⇒ Object
46 47 48 |
# File 'lib/cyoi/cli/provider.rb', line 46 def self.provider_cli(name) @provider_clis[name] end |
.register_provider_cli(name, klass) ⇒ Object
41 42 43 44 |
# File 'lib/cyoi/cli/provider.rb', line 41 def self.register_provider_cli(name, klass) @provider_clis ||= {} @provider_clis[name] = klass end |
Instance Method Details
#execute! ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cyoi/cli/provider.rb', line 13 def execute! unless valid_infrastructure? settings["provider"] ||= {} auto_detection unless settings.exists?("provider.name") choose_provider unless settings.exists?("provider.name") settings["provider"] = provider_cli.perform_and_return_attributes save_settings! end provider_cli.display_confirmation end |
#provider_cli ⇒ Object
Continue the interactive session with the user specific to the provider/infrastructure they have chosen.
The returned object is a class from cyoi/cli/providers/provier_cli_NAME.rb The class loads itself into ‘@provider_clis` via `register_provider_cli`
Returns nil if settings.provider.name not set
32 33 34 35 36 37 38 39 |
# File 'lib/cyoi/cli/provider.rb', line 32 def provider_cli @provider_cli ||= begin return nil unless name = settings.exists?("provider.name") require "cyoi/cli/providers/provider_cli_#{settings.provider.name}" klass = self.class.provider_cli(settings.provider.name) klass.new(settings.provider, hl) end end |