Class: KnifeInfo::Info

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_file_locationObject (readonly)

Returns the value of attribute config_file_location.



70
71
72
# File 'lib/chef/knife/info.rb', line 70

def config_file_location
  @config_file_location
end

#hostObject (readonly)

Returns the value of attribute host.



70
71
72
# File 'lib/chef/knife/info.rb', line 70

def host
  @host
end

#organizationObject (readonly)

Returns the value of attribute organization.



70
71
72
# File 'lib/chef/knife/info.rb', line 70

def organization
  @organization
end

#userObject (readonly)

Returns the value of attribute user.



70
71
72
# File 'lib/chef/knife/info.rb', line 70

def user
  @user
end

Instance Method Details

#long_printObject



61
62
63
64
65
66
67
68
# File 'lib/chef/knife/info.rb', line 61

def long_print
  <<-VERBOSE.gsub(/^\s+/, '')
    Host: #{@host}
    Username: #{username}
    Organization: #{@organization}
    Config File: #{@config_file}
  VERBOSE
end

#medium_printObject



57
58
59
# File 'lib/chef/knife/info.rb', line 57

def medium_print
  "#{user_string}#{@host}/#{organization}"
end

#read_config_dataObject



38
39
40
41
42
43
44
45
46
# File 'lib/chef/knife/info.rb', line 38

def read_config_data
  @config_file = Chef::Knife.locate_config_file

  uri = URI(server_url)
  @host = uri.host

  %r(.*/organizations/(?<org>.*)$) =~ uri.path
  @organization = org || ''
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chef/knife/info.rb', line 26

def run
  read_config_data

  unless @config_file.nil?
    case
    when config[:long] then ui.msg(long_print)
    when config[:medium] then ui.msg(medium_print)
    else ui.msg(tiny_print)
    end
  end
end

#tiny_printObject



52
53
54
55
# File 'lib/chef/knife/info.rb', line 52

def tiny_print
  %r(^(?<host>[a-zA-Z0-9-]+)\..*$) =~ @host
  "#{user_string}#{host}/#{@organization}"
end

#user_stringObject



48
49
50
# File 'lib/chef/knife/info.rb', line 48

def user_string
  (username != ENV['USER']) ? "#{username}@" : ''
end