2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source path is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the path LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
21 #include <folly/json/dynamic.h>
22 #include <folly/init/Init.h>
23 #include <folly/json/json.h>
25 #include "hphp/runtime/base/watchman.h"
27 #include "hphp/util/optional.h"
31 int main(int argc
, char** argv
) {
32 folly::Init _
{&argc
, &argv
};
35 std::cout
<< argv
[0] << " <root> [sock]" << std::endl
;
39 std::string root
= argv
[1];
40 HPHP::Optional
<std::string
> sock
;
48 folly::dynamic queryObj
;
49 std::cout
<< "Type a query, or 'b' for a basic query" << std::endl
50 << "Typing 's' will subscribe to the last query sent" << std::endl
;
51 while (!std::cin
.eof()) {
52 std::getline(std::cin
, line
);
57 queryObj
= folly::dynamic::object(
58 "fields", folly::dynamic::array("name", "exists"));
59 } else if (line
== "s") {
60 if (!queryObj
.isObject()) {
61 std::cout
<< "No query to subscribe to." << std::endl
;
64 Watchman::get(root
, sock
)
65 ->subscribe(queryObj
, [](folly::Try
<folly::dynamic
>&& results
) {
66 if (results
.hasValue()) {
67 std::cout
<< "Subscription got: "
68 << folly::toPrettyJson(results
.value()) << std::endl
;
69 } else if (results
.hasException()) {
70 std::cout
<< "Subscription error: " << results
.exception()
74 std::cout
<< "Subscribed using query " << folly::toPrettyJson(queryObj
)
79 queryObj
= folly::parseJson(line
);
80 } catch (const std::runtime_error
& e
) {
81 std::cout
<< "Couldn't parse " << line
<< ": " << e
.what() << std::endl
;
86 queryObj
["since"] = clock
;
88 if (!queryObj
.isObject()) {
92 folly::dynamic res
= Watchman::get(root
, sock
)->query(queryObj
).get();
93 std::cout
<< folly::toPrettyJson(res
) << std::endl
;
94 clock
= res
["clock"].asString();
95 } catch (const folly::AsyncSocketException
& e
) {
96 std::cout
<< e
.what() << std::endl
;