evalMemberCommand

Evaluate cmd as a CLI-like sub-command calling a member of agg of type T. Typically called with the args passed to a main function.

bool
evalMemberCommand
(
T
)
(
ref T agg
,
in string exe
,
in const(string)[] cmd
,)
if (
is(T == struct) ||
is(T == class)
)

Return Value

Type: bool

true iff the command cmd result in a call to T-member named cmd[1].

TODO: Use parameter flags

TODO: Auto-generate help description when --help is passed.

TODO: Support both - EXE scan("/tmp/") - EXE scan /tmp/ where the former is inputted in bash as EXE 'scan("/tmp/")'

Examples

import nxt.path : DirPath;

struct S {
version (none) @disable this(this);
@safe pure nothrow @nogc:
	void f1() scope {
		f1Count += 1;
	}
	void f2(int inc = 1) scope { // TODO: support f2:32
		f2Count += inc;
	}
	void scan(DirPath path) {
		_path = path;
		_scanDone = true;
	}
	private uint f1Count;
	uint f2Count;
	DirPath _path;
	bool _scanDone;
}
S s;

assert(!s.evalMemberCommand(null, []));
assert(s.evalMemberCommand(null, [""]));
assert(s.evalMemberCommand(null, ["_"]));

assert(s.f1Count == 0);
s.evalMemberCommand(null, ["f1"]);
// TODO: assert(s.f1Count == 1);

assert(s.f2Count == 0);
s.evalMemberCommand(null, ["f2"]); // TODO: call as "f2", "42"
// TODO: assert(s.f2Count == 1);

// TODO: assert(s._path == DirPath.init);
// TODO: assert(!s._scanDone);
// TODO: assert(s.evalMemberCommand(null, ["scan", "/tmp"]));
// TODO: assert(s._path == DirPath("/tmp"));
assert(s._scanDone);

Meta