如何为 RDoc::usage() 定义没有 === 标题的部分?

发布于 2024-07-14 09:45:10 字数 737 浏览 7 评论 0原文

我喜欢通过 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的部分?

I like to generate man pages using '--help' output via help2man and txt2man. Ruby's RDoc system is very convenient, but I can't seem to configure RDoc::usage in exactly the way that I want. Here's a sample script:

#!/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')

The output of the script looks like this:

Name
    foobar - Example command for StackOverflow question

Synopsis
    Usage: foobar [--help]

Options
    --help      This help message

But I would really like to suppress the "Name" and "Synopsis" headers for my usage output, but still mark them as sections for output to a man page.

Using the ':section:' markup works for RDoc::Rdoc, but not RDoc::usage. Is there an obvious way to mark sections for usage.rb without printing headers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮世清欢 2024-07-21 09:45:10

查看 RDoc 的源代码::usage_no_exit; 您有两种方法可以挂钩它的内部来实现您想要的:

  1. 设置ENV['RI']以强制执行不同的格式化选项(包括指定自定义格式化程序类),或
  2. 重新定义默认值RI::TextFormatter 的 display_heading(和/或其他方法)(不)显示标题或其他内容

    需要“rdoc/usage” 
      需要“rdoc/ri/ri_formatter” 
    
      模块RI 
        类 TextFormatter 
          def 显示标题 
            # 没有 
          结尾 
        结尾 
      结尾 
    
      RDoc::usage('名称') 
      

Look at the source code for RDoc::usage_no_exit; you have two ways of hooking to its guts to achieve what yyou desire:

  1. Set ENV['RI'] to enforce different formatting options (including specifying a custom formatter class), or
  2. Redefine the default RI::TextFormatter's display_heading (and/or other methods) to (not) display the headings or whatever else

    require 'rdoc/usage'
    require 'rdoc/ri/ri_formatter'
    
    module RI
      class TextFormatter
        def display_heading
          # nop
        end
      end
    end
    
    RDoc::usage('name')
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文