Module: KubsCLI

Defined in:
lib/kubs_cli.rb,
lib/kubs_cli/cli.rb,
lib/kubs_cli/copy.rb,
lib/kubs_cli/pull.rb,
lib/kubs_cli/install.rb,
lib/kubs_cli/version.rb,
lib/kubs_cli/file_helper.rb,
lib/kubs_cli/configuration.rb

Overview

Top level class

Defined Under Namespace

Classes: CLI, Configuration, Copy, Error, FileHelper, Install, Pull

Constant Summary collapse

EXAMPLES =

Location of default config and dependencies

File.join(File.expand_path(__dir__), 'examples')
VERSION =
'0.2.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



35
36
37
# File 'lib/kubs_cli/configuration.rb', line 35

def self.configuration
  @configuration ||= Configuration.new
end

.errorsObject

Returns the value of attribute errors.



19
20
21
# File 'lib/kubs_cli.rb', line 19

def errors
  @errors
end

Class Method Details

.add_error(e:, msg: nil) ⇒ Object

Adds an error to KubsCLI#errors return Array<Error> Implicitly reutrns the array of errors

Parameters:

  • e (Error)

    Error raised

  • msg (String) (defaults to: nil)

    Message to display



28
29
30
# File 'lib/kubs_cli.rb', line 28

def add_error(e:, msg: nil)
  KubsCLI.errors << e.exception(msg)
end

.clear_errorsObject

Resets errors to a blank array



38
39
40
# File 'lib/kubs_cli.rb', line 38

def clear_errors
  @errors = []
end

.configure {|configuration| ... } ⇒ Object

Yields:



30
31
32
33
# File 'lib/kubs_cli/configuration.rb', line 30

def self.configure
  @configuration ||= Configuration.new
  yield(configuration)
end

.create_config_dir(path = File.join(Dir.home, '.kubs')) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/kubs_cli/configuration.rb', line 53

def self.create_config_dir(path = File.join(Dir.home, '.kubs'))
  fh = FileHelper.new

  puts "Creating a default configuration files @ #{path}"
  fh.mkdirs(path)

  Dir["#{EXAMPLES}/*"].each do |file|
    fh.copy(from: file, to: path)
  end
end

.load_configuration(file = File.join(Dir.home, '.kubs', 'config.rb')) ⇒ Object

Raises:

  • (Exception)


43
44
45
46
47
48
49
50
51
# File 'lib/kubs_cli/configuration.rb', line 43

def self.load_configuration(file = File.join(Dir.home, '.kubs', 'config.rb'))
  msg = 'Unable to location a configuration file. The default location is'
  msg += '$HOME/.kubs/config.rb'
  msg += "\nTo create a standard default config, run 'kubs init'"

  raise Exception, msg unless File.exist?(file)

  load file
end

Prints the errors when finished running



33
34
35
# File 'lib/kubs_cli.rb', line 33

def print_errors
  KubsCLI.errors.each { |e| puts e.message }
end

.reset_configurationObject



39
40
41
# File 'lib/kubs_cli/configuration.rb', line 39

def self.reset_configuration
  @configuration = Configuration.new
end