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.



66
67
68
# File 'lib/chef/knife/info.rb', line 66

def config_file_location
  @config_file_location
end

#hostObject (readonly)

Returns the value of attribute host.



66
67
68
# File 'lib/chef/knife/info.rb', line 66

def host
  @host
end

#organizationObject (readonly)

Returns the value of attribute organization.



66
67
68
# File 'lib/chef/knife/info.rb', line 66

def organization
  @organization
end

#userObject (readonly)

Returns the value of attribute user.



66
67
68
# File 'lib/chef/knife/info.rb', line 66

def user
  @user
end

Instance Method Details

#long_printObject



57
58
59
60
61
62
63
64
# File 'lib/chef/knife/info.rb', line 57

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

#medium_printObject



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

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

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/knife/info.rb', line 26

def run
  @config_file_location = Chef::Knife.locate_config_file

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

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

  if config[:long]
    ui.msg(long_print)
  elsif config[:medium]
    ui.msg(medium_print)
  else config[:tiny]
    ui.msg(tiny_print)
  end
end

#tiny_printObject



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

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

#user_stringObject



44
45
46
# File 'lib/chef/knife/info.rb', line 44

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