如何定义没有=== RDhe :: usage()的标题的部分?
题
我喜欢通过help2man和txt2man使用'--help'输出生成手册页。 Ruby的RDoc系统非常方便,但我似乎无法完全按照我想要的方式配置RDoc :: usage。这是一个示例脚本:
#!/usr/bin/env ruby
#
# === Name
#
# foobar - Example command for StackOverflow question
#
# === Synopsis
#
# Usage: foobar [--help]
#
# === Options
#
# --help This help message
require 'rdoc/usage'
RDoc::usage('name', 'synopsis', 'options')
脚本的输出如下所示:
Name
foobar - Example command for StackOverflow question
Synopsis
Usage: foobar [--help]
Options
--help This help message
但我真的想压制“姓名”。和“概要”我的使用输出的标题,但仍然将它们标记为输出到手册页的部分。
使用':section:'标记适用于RDoc :: Rdoc,但不适用于RDoc :: usage。是否有一种明显的方法来标记usage.rb的部分而不打印标题?
解决方案
查看 <的源代码代码>的RDoc :: usage_no_exit 代码> ;你有两种方法可以达到你想要的目标:
- 设置
ENV ['RI']
以强制执行不同的格式设置选项(包括指定自定义格式化程序类),或 -
重新定义默认RI :: TextFormatter的 display_heading (和/或其他方法)来(不)显示标题或其他任何内容
require 'rdoc/usage' require 'rdoc/ri/ri_formatter' module RI class TextFormatter def display_heading # nop end end end RDoc::usage('name')
醇>
不隶属于 StackOverflow