【问题标题】:what is the purpose of #: (hashtag/pound colon) in bash#: (hashtag/磅冒号) in bash 的目的是什么
【发布时间】:2016-08-16 23:35:46
【问题描述】:

我最近在查看 Homebrew 源代码。由于它是一种流行的工具,因此代码可能相对干净。我注意到他们使用#: 评论风格(例如:update.sh)。我在其他任何地方都没有看到过(而且很难搜索符号,所以我找不到任何提及它的内容)。这是公认的约定吗?有什么特殊含义吗?

【问题讨论】:

    标签: bash comments sh hashtag


    【解决方案1】:

    它看起来像是联机帮助页的某种文档片段:它以标准联机帮助页样式编写,并记录了后面的脚本。这在Library/Homebrew/cmd/vendor-install.sh 中更加明显,可以找到类似的评论,并带有@hide_from_man_page 的标签:

    #: @hide_from_man_page
    #:  * `vendor-install` [<target>]:
    #:     Install vendor version of Homebrew dependencies.
    

    因此,据推测,所有未如此注释的片段都包含在手册页中。

    不过,您选择了一个不幸的示例,因为 update 被认为是“基本命令”,因此记录在手册页的单独部分中。让我们选择一个非必要的命令,例如style,您可以在Library/Homebrew/cmd/style.rb 中找到它:

    #:  * `style` [`--fix`] [`--display-cop-names`] [<formulae>|<files>]:
    #:    Check formulae or files for conformance to Homebrew style guidelines.
    #:
    #:    <formulae> is a list of formula names.
    #:
    #:    <files> is a list of file names.
    #:
    #:    <formulae> and <files> may not be combined. If both are omitted, style will run
    #:    style checks on the whole Homebrew `Library`, including core code and all
    #:    formulae.
    #:
    #:    If `--fix` is passed and `HOMEBREW_DEVELOPER` is set, style violations
    #:    will be automatically fixed using RuboCop's `--auto-correct` feature.
    #:
    #:    If `--display-cop-names` is passed, the RuboCop cop name for each violation
    #:    is included in the output.
    #:
    #:    Exits with a non-zero status if any style violations are found.
    

    现在,当您查看 Library/Homebrew/manpages/brew.1.md.erb 时,您会发现它们是确实手册页片段,它们会自动包含在主要的 brew.1 手册页中:

    # To make changes to this man page:
    #
    # - For changes to a specific command (appears in the `COMMANDS` section):
    #   - Edit the top comment in `Library/Homebrew/cmd/<command>.{rb,sh}`.
    #   - Make sure to use the line prefix `#:` for the comments to be recognized as
    #     documentation. If in doubt, compare with already documented commands.
    # - For other changes: Edit this file.
    #
    # When done, regenerate the man page and its HTML version by running `brew man`.
    

    还有here's the line where they get included into the manpage:

    <%= commands.join("\n") %>
    

    你可以在share/man/man1/brew.1看到生成的输出:

    .TP
    \fBstyle\fR [\fB\-\-fix\fR] [\fB\-\-display\-cop\-names\fR] [\fIformulae\fR|\fIfiles\fR]
    Check formulae or files for conformance to Homebrew style guidelines\.
    .
    .IP
    \fIformulae\fR is a list of formula names\.
    .
    .IP
    \fIfiles\fR is a list of file names\.
    .
    .IP
    \fIformulae\fR and \fIfiles\fR may not be combined\. If both are omitted, style will run style checks on the whole Homebrew \fBLibrary\fR, including core code and all formulae\.
    .
    .IP
    If \fB\-\-fix\fR is passed and \fBHOMEBREW_DEVELOPER\fR is set, style violations will be automatically fixed using RuboCop\'s \fB\-\-auto\-correct\fR feature\.
    .
    .IP
    If \fB\-\-display\-cop\-names\fR is passed, the RuboCop cop name for each violation is included in the output\.
    .
    .IP
    Exits with a non\-zero status if any style violations are found\.
    .
    

    share/doc/homebrew/brew.1.html:

    <dt><code>style</code> [<code>--fix</code>] [<code>--display-cop-names</code>] [<var>formulae</var>|<var>files</var>]</dt><dd><p>Check formulae or files for conformance to Homebrew style guidelines.</p>
    
    <p><var>formulae</var> is a list of formula names.</p>
    
    <p><var>files</var> is a list of file names.</p>
    
    <p><var>formulae</var> and <var>files</var> may not be combined. If both are omitted, style will run
    style checks on the whole Homebrew <code>Library</code>, including core code and all
    formulae.</p>
    
    <p>If <code>--fix</code> is passed and <code>HOMEBREW_DEVELOPER</code> is set, style violations
    will be automatically fixed using RuboCop's <code>--auto-correct</code> feature.</p>
    
    <p>If <code>--display-cop-names</code> is passed, the RuboCop cop name for each violation
    is included in the output.</p>
    

    我不知道这是否是 shell 脚本中公认的约定,但类似的约定用于各种语言和/或文档工具,例如JavaDoc (/**)、Doxygen (/**/*!/////!)、JsDoc (/**) 或 C♯ (///)。

    【讨论】:

      猜你喜欢
      • 2011-03-14
      • 2015-02-11
      • 2016-10-16
      • 2011-03-01
      • 1970-01-01
      • 2012-09-25
      • 2019-09-14
      • 2016-05-16
      • 1970-01-01
      相关资源
      最近更新 更多