evalMemberCommand

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

bool
evalMemberCommand
(
T
)
(
ref T arg
,
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[0].

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([]));
assert(!s.evalMemberCommand([""]));
assert(!s.evalMemberCommand(["_"]));

assert(s.f1Count == 0);
s.evalMemberCommand(["f1"]);
assert(s.f1Count == 1);

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

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

Meta