summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2011-06-02 16:57:35 -0700
committerBryan McLellan <btm@opscode.com>2011-06-02 16:57:35 -0700
commit9c3ebd4695cd88b9f1a4004770937bfc898feaf9 (patch)
tree626f921401ccb5558393f221117483e23326de09
parent1fbc7d28d640b4b683472b19f7b979f53f9ed4de (diff)
downloadchef-9c3ebd4695cd88b9f1a4004770937bfc898feaf9.tar.gz
CHEF-2316: Switch to a list based system for knife help rather than glob
-rw-r--r--chef/Rakefile17
-rw-r--r--chef/lib/chef/knife/help.rb25
-rw-r--r--chef/lib/chef/knife/help_topics.rb4
3 files changed, 33 insertions, 13 deletions
diff --git a/chef/Rakefile b/chef/Rakefile
index 1a8a1ec09e..897b414c80 100644
--- a/chef/Rakefile
+++ b/chef/Rakefile
@@ -67,6 +67,22 @@ namespace :docs do
desc "Regenerate HTML manual from markdown"
task :html
+ desc "Regenerate help topics from man pages"
+ task :list => :man do
+ topics = Array.new
+
+ Dir['distro/common/man/man1/*.1'].each do |man|
+ topics << File.basename(man, '.1')
+ end
+
+ File.open('lib/chef/knife/help_topics.rb', 'w') do |f|
+ f.puts "# Do not edit this file by hand"
+ f.puts "# This file is autogenerated by the docs:list rake task from the available manpages\n\n"
+
+ f.puts "HELP_TOPICS = #{topics.inspect}"
+ end
+ end
+
if system('which ronn > /dev/null')
['distro/common/markdown/man1/*.mkd', 'distro/common/markdown/man8/*.mkd'].each do |dir|
Dir[dir].each do |mkd|
@@ -87,7 +103,6 @@ namespace :docs do
file(htmlfile => mkd) do
sh "ronn -5 #{RONN_OPTS} --style=toc #{mkd} --pipe > #{htmlfile}"
end
-
task :html => htmlfile
end
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"]