diff options
author | Bryan McLellan <btm@opscode.com> | 2011-06-02 18:18:21 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2011-06-02 18:18:21 -0700 |
commit | a3ea78442217360fa6a1c742fba4128066915299 (patch) | |
tree | ebeb8b7f83b4a1ac7dcbfbec6a2dcf1ce1fb5a11 /chef/lib | |
parent | 16dd475cd3470de9f1f3818c22916ba6670b806f (diff) | |
parent | 74d0b2b20427f1444cf378cb00d2cdb75ee6a9cb (diff) | |
download | chef-a3ea78442217360fa6a1c742fba4128066915299.tar.gz |
Merge branch 'CHEF-2316'
Diffstat (limited to 'chef/lib')
-rw-r--r-- | chef/lib/chef/knife/help.rb | 25 | ||||
-rw-r--r-- | chef/lib/chef/knife/help_topics.rb | 4 |
2 files changed, 17 insertions, 12 deletions
diff --git a/chef/lib/chef/knife/help.rb b/chef/lib/chef/knife/help.rb index 7a740d04ff..13fe674704 100644 --- a/chef/lib/chef/knife/help.rb +++ b/chef/lib/chef/knife/help.rb @@ -55,23 +55,25 @@ MOAR_HELP @topic = find_manpages_for_query(@query) end - manpage_path = available_manpages_by_basename[@topic] + manpage_path = find_manpage_path(@topic) exec "man #{manpage_path}" end def help_topics - available_manpages_by_basename.keys.map {|c| c.sub(/^knife\-/, '')}.sort + # The list of help topics is generated by a rake task from the available man pages + # This constant is provided in help_topics.rb which is automatically required/loaded by the knife subcommand loader. + HELP_TOPICS end def print_help_topics ui.info "Available help topics are: " - help_topics.each do |topic| + help_topics.collect {|t| t.gsub(/knife-/, '') }.sort.each do |topic| ui.msg " #{topic}" end end def find_manpages_for_query(query) - possibilities = available_manpages_by_basename.keys.select do |manpage| + possibilities = help_topics.select do |manpage| ::File.fnmatch("knife-#{query}*", manpage) || ::File.fnmatch("#{query}*", manpage) end if possibilities.empty? @@ -87,16 +89,15 @@ MOAR_HELP end end - def available_manpages_by_basename - @available_manpages_by_basename ||= begin - available_manpages = Dir[File.expand_path("../distro/common/man/man1/knife-*1", CHEF_ROOT), "/usr/share/man/man1/knife-*{.1,.1.gz}"] - available_manpages.inject({}) do |map, manpath| - map[::File.basename(manpath).gsub(/.1.*/, '')] = manpath - map - end + def find_manpage_path(topic) + if ::File.exists?(::File.expand_path("../distro/common/man/man1/#{topic}.1", CHEF_ROOT)) + # If we've provided the man page in the gem, give that + return ::File.expand_path("../distro/common/man/man1/#{topic}.1", CHEF_ROOT) + else + # Otherwise, we'll just be using MANPATH + topic end end - end end end diff --git a/chef/lib/chef/knife/help_topics.rb b/chef/lib/chef/knife/help_topics.rb new file mode 100644 index 0000000000..90f638f357 --- /dev/null +++ b/chef/lib/chef/knife/help_topics.rb @@ -0,0 +1,4 @@ +# Do not edit this file by hand +# This file is autogenerated by the docs:list rake task from the available manpages + +HELP_TOPICS = ["knife-ssh", "knife-environment", "knife-bootstrap", "knife-cookbook", "knife-exec", "knife-tag", "knife-status", "knife", "knife-data-bag", "knife-index", "knife-configure", "knife-search", "knife-node", "knife-client", "shef", "knife-role", "knife-cookbook-site"] |