2014-06-13 37 views
1

我们使用Boost-Build来构建我们的软件。为了帮助实现这一点,我们编写了一个规则和行动库。 Boost-Build允许传入命令行参数,并传递任何以--为前缀的参数。目前,得到的参数保持和检查我们正在做这样的事情国旗:在帮助系统中注册命令行参数:Boost-Build

import modules ; 

local args = [ modules.peek : ARGV ] ; 
# or like this 
if "--my-flag" in [ modules.peek : ARGV ] 

其工作是获取和校验值。但是,使用Boost-Build和我们的果酱库的开发人员不知道这些标志是否可用,并且希望在运行bjam -hbjam --help时看到这些标志的一些帮助。我看到BB有一个help模块,但我没有看到任何方法向帮助系统注册参数。

有没有办法注册命令行标志,并附上简短的文档,帮助系统会选择?

回答

1

在回答我的问题,我已经添加了非常的功能,我问:https://github.com/boostorg/build/pull/23

它利用现有选项的插件系统。无论何时你想创建一个新的命令行选项,在options目录中创建一个新模块。在该新模块中,创建一个保存值或为空的变量。在变量上方创建评论。该注释用作命令行文档,并且该值(如果给出)用于描述该变量的默认值。

在新模块中创建process规则并向系统注册您的选项。这允许导入option模块并从单一来源获取值。这要求每个变量名都以模块的名称作为前缀。

创建一个名为.option-description的变量。它的值是部分分隔符,它的注释是部分的描述。

例如:

# within options/cool.jam 

# These are the options for the Cool option plugin 
.option-description = Cool Options 

# This enables option1 
.option.--cool-option1 ?= ; 

# This enables something cool 
.option.--cool-default-option ?= "my default value" ; 

rule process (
    command # The option. 
    : values * # The values, starting after the "=". 
    ) 
{ 
    option.set $(command) : $(values) ; 
} 

当与--help-options标志运行bjam,它会输出下面的options目录内完成上述图形的所有模块。这将有类似以下的输出:

Boost.Build Usage: 

    b2 [ options... ] targets... 

    * -a; Build all targets, even if they are current. 
    * -fx; Read 'x' as the Jamfile for building instead of searching for the 
    Boost.Build system. 
    * -jx; Run up to 'x' commands concurrently. 
    * -n; Do not execute build commands. Instead print out the commands as they 
    would be executed if building. 
    * -ox; Output the used build commands to file 'x'. 
    * -q; Quit as soon as a build failure is encountered. Without this option 
    Boost.Jam will continue building as many targets as it can. 
    * -sx=y; Sets a Jam variable 'x' to the value 'y', overriding any value that 
    variable would have from the environment. 
    * -tx; Rebuild the target 'x', even if it is up-to-date. 
    * -v; Display the version of b2. 
    * --x; Any option not explicitly handled by Boost.Build remains available to 
    build scripts using the 'ARGV' variable. 
    * --abbreviate-paths; Use abbreviated paths for targets. 
    * --hash; Shorten target paths by using an MD5 hash. 
    * -dn; Enables output of diagnostic messages. The debug level 'n' and all 
    below it are enabled by this option. 
    * -d+n; Enables output of diagnostic messages. Only the output for debug 
    level 'n' is enabled. 

Debug Levels: 

    Each debug level shows a different set of information. Usually with higher 
    levels producing more verbose information. The following levels are supported: 

    * 0; Turn off all diagnostic output. Only errors are reported. 
    * 1; Show the actions taken for building targets, as they are executed. 
    * 2; Show quiet actions and display all action text, as they are executed. 
    * 3; Show dependency analysis, and target/source timestamps/paths. 
    * 4; Show arguments of shell invocations. 
    * 5; Show rule invocations and variable expansions. 
    * 6; Show directory/header file/archive scans, and attempts at binding to 
    targets. 
    * 7; Show variable settings. 
    * 8; Show variable fetches, variable expansions, and evaluation of 'if' 
    expressions. 
    * 9; Show variable manipulation, scanner tokens, and memory usage. 
    * 10; Show execution times for rules. 
    * 11; Show parsing progress of Jamfiles. 
    * 12; Show graph for target dependencies. 
    * 13; Show changes in target status (fate). 

Cool Options: 
    These are the options for the Cool option plugin 

    * --cool-option1: This enables option1. Default is disabled. 
    * --cool-default-option: This enables something cool. "my default value". 

后来在自己的卡纸代码,然后你可以通过做您可以通过注册期权值保持:

import option ; 

option1 = option.get '--cool-option1' ; 
if $(option1) { 
    # do_something ; 
} 
1

无法使用B2帮助系统“注册”单个选项。一般来说,这只是帮助系统的工作方式。帮助系统仅记录B2模块(即类别)和项目(即堵塞文件)。当您执行“b2 --help”时看到的内容是项目帮助信息和模块信息的集合。所有数据都是从解析jamfiles中提取的。

对于为类和参数添加注释的模块,它们被格式化输出。例如,看看“container.jam”的来源。在这个文件的第二个评论是模块帮助文档,“class node”之前的评论是一个类帮助文档,“rule set”之前的评论是一个方法帮助文档,以及“value?”之后的评论。参数是一个帮助文档。

对于项目,项目的jamfile中的第二条评论被视为帮助文档。例如,Boost Jamroot对于使用信息有很大的帮助文档评论。这是打印出来,如果你:

cd <boost-root> 
b2 --help 

如果你对你的项目的Jamfiles一个这样的评论(注:它假定第一个注释是一个版权声明,因此跳过它,并使用第二注释块的帮助doc),然后cd到该项目目录,并执行b2 --help您应该看到它打印。

你想要哪种类型的帮助文档当然取决于你的项目和你的意图。