8. 命令行界面¶
mappyfile包含两个命令行应用程序, 格式 和 验证 . 命令行界面(CLI)允许将mapyfile轻松集成到Travis和Appveyor等持续集成(CI)平台中,并自动验证和格式化映射文件。
8.1. 格式¶
这个 format
命令可用于对映射文件应用一致的格式和空白,以及删除注释。它具有与 save 函数相同的参数。
使用默认格式设置将 valid.map
格式化为新的 valid_formatted.map
文件,使用以下语法:
mappyfile format valid.map valid_formatted.map
其他示例包括在 help
命令的文档,如下所示。要在命令行中显示此命令,请运行以下命令:
mappyfile format --help
Usage: mappyfile format [OPTIONS] INPUT_MAPFILE OUTPUT_MAPFILE
Format a the input-mapfile and save as output-mapfile. Note output-mapfile
will be overwritten if it already exists.
Example of formatting a single Mapfile:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map
Example of formatting a single Mapfile with single quotes and tabs for
indentation:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map
--quote=\' --indent=1 --spacer=
Example of formatting a single Mapfile without expanding includes, but
including comments:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map --no-
expand --comments
Options:
--indent INTEGER The number of spacer characters to indent
structures in the Mapfile [default: 4]
--spacer TEXT The character to use for indenting structures in
the Mapfile
--quote TEXT The quote character to use in the Mapfile
(double or single quotes). Ensure these are
escaped e.g. \" or \' [default: \"]
--newlinechar TEXT The character used to insert newlines in the
Mapfile [default: \n]
--expand / --no-expand Expand any INCLUDE directives found in the
Mapfile [default: True]
--comments / --no-comments Keep Mapfile comments in the output
(experimental) [default: False]
--help Show this message and exit.
8.2. 验证¶
这个 validate
命令可用于检查映射文件中使用的值是否有效,方法是将其内容与映射文件架构进行比较。它的参数与 validate 功能相同。
mappyfile还允许针对不同版本的MapServer进行验证,例如验证mapserver7.0或7.6的Mapfiles。
注解
使用通配符搜索映射文件时,在Windows上使用 python glob
模块。这只搜索一级深度的子文件夹。在Linux上,通配符通常在shell中展开,因此可以验证任何深度子文件夹中的映射文件。
如果在映射文件中遇到验证错误,它们将显示在控制台输出中,如下所示:
C:/Temp/map1.map validated successfully
C:/Temp/map2.map validated successfully
C:/Temp/map3.map (Line: 16 Column: 3) ERROR: Invalid value in TYPE - u'polyline' is not one of [u'chart', u'circle', u'line', u'point', u'polygon', u'raster', u'query', u'annotation']
3 file(s) validated (2 successfully)
8.2.1. 例1¶
要验证 ms-ogc-workshop
文件夹和所有子文件夹中的所有映射文件:
mappyfile validate D:\ms-ogc-workshop\ms4w\apps\ms-ogc-workshop\**\*.map
8.2.3. 例3¶
要验证MapServer 7.6版的映射文件,请执行以下操作:
mappyfile validate /world.map --version=7.6
要显示命令的帮助文本,请运行以下命令:
mappyfile validate --help
Usage: mappyfile validate [OPTIONS] [MAPFILES]...
Validate Mapfile(s) against the Mapfile schema
The MAPFILES argument is a list of paths, either to individual Mapfiles,
or a folders containing Mapfiles. Wildcards are supported (natively on
Linux, and up to one level deep on Windows). Validation errors are
reported to the console. The program returns the error count - this will
be 0 if no validation errors are encountered.
Example of validating a single Mapfile:
mappyfile validate C:/Temp/valid.map
Example of validating two folders containing Mapfiles, without expanding
INCLUDES:
mappyfile validate C:/Temp/*.map
D:/GitHub/mappyfile/tests/mapfiles/*.map --no-expand
Options:
--expand / --no-expand Expand any INCLUDE directives found in the Mapfile
[default: True]
--help Show this message and exit.
8.3. 图式¶
将映射文件架构保存到文件中。设置version参数以输出特定版本。
mappyfile schema --help
Usage: mappyfile format [OPTIONS] INPUT_MAPFILE OUTPUT_MAPFILE
Format a the input-mapfile and save as output-mapfile. Note output-mapfile
will be overwritten if it already exists.
Example of formatting a single Mapfile:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map
Example of formatting a single Mapfile with single quotes and tabs for
indentation:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map
--quote=\' --indent=1 --spacer=
Example of formatting a single Mapfile without expanding includes, but
including comments:
mappyfile format C:/Temp/valid.map C:/Temp/valid_formatted.map --no-
expand --comments
Options:
--indent INTEGER The number of spacer characters to indent
structures in the Mapfile [default: 4]
--spacer TEXT The character to use for indenting structures in
the Mapfile
--quote TEXT The quote character to use in the Mapfile
(double or single quotes). Ensure these are
escaped e.g. \" or \' [default: \"]
--newlinechar TEXT The character used to insert newlines in the
Mapfile [default: \n]
--expand / --no-expand Expand any INCLUDE directives found in the
Mapfile [default: True]
--comments / --no-comments Keep Mapfile comments in the output
(experimental) [default: False]
--help Show this message and exit.