CommandPipe

Communicate with the launched program through stdio pipes.

gendoc responds to requests from the launched guest program. One request or response communicates via a JSON object without lines. Guest program requests are passed line by line to the standard error output. gendoc responds to requests with one line. The request starts with ::gendoc-request::, followed by a JSON string.

::gendoc-request::{ "type": "ReqEcho", "value": {"msg": "test"} }

The response type corresponds to the request type.

| Request Type | Response Type | |:----------------------|:---------------------| | ReqEcho | ResEcho, ResErr | | ReqInfo | ResInfo, ResErr |

Each piece of information is composed of a JSON object composed of type and value as follows, and the value includes a payload. The following examples include line breaks and indents for readability, but do not break lines in the data actually used.

{
 "type":  "ReqInfo",
 "value": { }
}

Constructors

this
this(Config cfg, DubPkgInfo[] pkgInfo)

Members

Functions

result
auto result()
run
void run(string[] args, string workDir, string[string] env)
void run(string args, string workDir, string[string] env)
status
int status()
stderr
auto stderr()
stdout
auto stdout()

Examples

import std.path;
gendoc.config.Config cfg;
ModuleManager modmgr;
modmgr.addSources("root", "v1.2.3", __FILE_FULL_PATH__.buildNormalizedPath("../.."), [__FILE__], null);
auto pipe = CommandPipe(cfg, modmgr.dubPackages);
pipe.run("echo xxx");
pipe.run(["rdmd", "--eval", q{
	stderr.writeln(`test1`);
	stderr.writeln(`::gendoc-request::{ "type": "ReqEcho", "value": {"msg": "test-echo"} }`);
	stderr.writeln(`test2`);
	auto res = stdin.readln();
	writeln(parseJSON(res)["value"]["msg"].str);

	stderr.writeln(`::gendoc-request::{ "type": "XXXXX", "value": {"msg": "test"} }`);
	res = stdin.readln();
	writeln(parseJSON(res)["value"]["msg"].str);

	stderr.writeln(`::gendoc-request::{ "type": "ReqInfo", "value": {} }`);
	res = stdin.readln();
	writeln(parseJSON(res)["value"]["dubPkgInfos"][0]["packageVersion"].str);
}]);
assert(pipe.stderr.equal(["test1", "test2"]));
assert(pipe.stdout.equal(["xxx", "test-echo", "Unknown request type.", "v1.2.3"]));
assert(pipe.result.equal(["xxx", "test1", "test2", "test-echo", "Unknown request type.", "v1.2.3"]));
assert(pipe.status == 0);

Meta