use add_commandn where possible

master
Daniel Kolesa 2016-08-01 00:16:22 +01:00
parent a36e9d021a
commit 7c5223ca19
1 changed files with 12 additions and 10 deletions

22
main.cc
View File

@ -594,16 +594,18 @@ int main(int argc, char **argv) {
)); ));
}); });
osv.add_command("extreplace", "sss", []( osv.add_commandn("extreplace", "sss", [](
cscript::CsState &cs, char const *lst, ObState &os, TvalRange args
char const *oldext, char const *newext
) { ) {
ConstCharRange lst = args[0].get_strr();
ConstCharRange oldext = args[1].get_strr();
ConstCharRange newext = args[2].get_strr();
String ret; String ret;
if (oldext[0] == '.') { if (oldext.front() == '.') {
++oldext; oldext.pop_front();
} }
if (newext[0] == '.') { if (newext.front() == '.') {
++newext; newext.pop_front();
} }
auto fnames = cscript::util::list_explode(lst); auto fnames = cscript::util::list_explode(lst);
for (ConstCharRange it: fnames.iter()) { for (ConstCharRange it: fnames.iter()) {
@ -619,11 +621,11 @@ int main(int argc, char **argv) {
ret += it; ret += it;
} }
} }
cs.result->set_str(ostd::move(ret)); os.result->set_str(ostd::move(ret));
}); });
osv.add_command("invoke", "s", [](ObState &os, char const *name) { osv.add_commandn("invoke", "s", [](ObState &os, TvalRange args) {
os.result->set_int(os.exec_main(name)); os.result->set_int(os.exec_main(args[0].get_strr()));
}); });
cs_register_globs(osv); cs_register_globs(osv);