跳到主要内容

version

version 命令会告诉你当前运行的 watchman 服务的版本和构建信息

$ watchman version
{
"version": "2.9.6",
"buildinfo": "git:2727d9a1e47a4a2229c65cbb2f0c7656cbd96270"
}

获取客户端的版本

$ watchman -v
2.9.8

如果服务器和客户端版本不匹配,你可能需要重启服务器:watchman shutdown-server ; watchman

功能

自 3.8 起。

version 命令可用于检查命名的功能。功能使得更容易根据功能的名称来检查服务器是否实现了该功能,而不是让客户端构建关于何时引入这些功能的知识。

你可以阅读更多关于 可用的功能名称

检查是否支持 relative_root 功能

$ watchman -j <<< '["version", {"optional":["relative_root"]}]'
{
"version": "3.8.0",
"capabilities": {
"relative_root": true
}
}

如果不支持该功能

$ watchman -j <<< '["version", {"optional":["will-never-exist"]}]'
{
"version": "3.8.0",
"capabilities": {
"will-never-exist": false
}
}

如果不支持该功能,让服务器生成错误响应

$ watchman -j <<< '["version", {"required":["will-never-exist"]}]'
{
"version": "3.8.0",
"capabilities": {
"will-never-exist": false
},
"error": "client required capability `will-never-exist` is not supported by this server"
}

需要一个特性,并测试是否支持某些可选特性

$ watchman -j <<< '["version", {"required":["term-match"],"optional":["a","b"]}]'
{
"version": "3.8.0",
"capabilities": {
"a": false,
"b": false,
"term-match": true
}
}

capabilityCheck

nodepython 客户端提供了一个 capabilityCheck 方法,它将执行上面的版本检查,并且还提供对针对较旧版本的 watchman 服务器测试功能支持的有限支持。 这有助于从基于版本号的检查到基于功能名称的检查的更平滑的过渡。

python

import pywatchman
client = pywatchman.client()
# will throw an error if any of the required names are not supported
res = client.capabilityCheck(optional=['a'], required=['term-match'])
print res
# {'version': '3.8.0', 'capabilities': {'term-match': True, 'a': False}}

node

var watchman = require('fb-watchman');
var client = new watchman.Client();
client.capabilityCheck({optional:['a'], required:['term-match']},
function (error, resp) {
if (error) {
// error will be an Error object if any of the required named
// are not supported
}
console.log(resp);
// {'version': '3.8.0', 'capabilities': {'term-match': false, 'a': false}}
client.end();
});