remotemon
Version:
remote monitoring, since there is no ansible for raspberry pi.
1,604 lines (1,603 loc) • 80.7 kB
JavaScript
#!/usr/bin/env node
var ref$, global_data, com, print, readJson, most, exec, chokidar, most_create, fs, metadata, optionParser, tampax, readline, emphasize, child_process, rm_empty_lines, path, dotpat, spawn, yaml, compare_version, boxen, moment, l, z, zj, j, R, lit, c, wait, noop, jspc, be, guard, cp, os, homedir, release, re, isWSL, CONFIG_FILE_NAME, cmd_data, question_init, rest, E, str, silent, edit, concatenate, isvar, check_if_number, vars, args, init, V, defarg_main, inpwd_str, san_arr, san_user_script, run_script, x$, gs_path, y$, z$, get_str_type, handle_path_dot, symbol_script, rm_merge_key, san_defarg, update_defarg, yaml_parse, re_curly, get_curly, tampax_abs, clear, merge_ref_defarg, check_if_circular_ref, replace_dot, pathops, modyaml, parseDoc, show, nPromise, rmdef, only_str, SERR, OK, tampax_parse, mergeArray, unu, is_false, is_true, ifTrue, san_remotefold, rsync_arr2obj, ifrsh, organize_rsync, dangling_colon, handle_ssh, str_to_num, disp, zero, check_if_empty, create_logger, update, init_continuation, arrToStr, create_rsync_cmd, exec_finale, exec_rsync, bko, check_if_remote_not_defined, check_if_remotehost_present, check_if_remotedir_present, remote_main_proc, onchange, diff, handle_inf, resolve_signal, save_failed_build, print_final_message, restart, CF_Signal, simp_path, ms_create_watch, if_current_hist_empty, getunique, exec_list_hist, start_from_resume_point, get_all, rm_resume, main, slice$ = [].slice, arrayFrom$ = Array.from || function(x){return slice$.call(x);};
ref$ = require("./data"), global_data = ref$.global_data, com = ref$.com, print = ref$.print;
readJson = com.readJson, most = com.most, exec = com.exec, chokidar = com.chokidar, most_create = com.most_create;
fs = com.fs, metadata = com.metadata, optionParser = com.optionParser, tampax = com.tampax, readline = com.readline;
emphasize = com.emphasize, child_process = com.child_process, rm_empty_lines = com.rm_empty_lines, path = com.path;
dotpat = com.dotpat, spawn = com.spawn, yaml = com.yaml, compare_version = com.compare_version, boxen = com.boxen, moment = com.moment;
ref$ = com.hoplon.utils, l = ref$.l, z = ref$.z, zj = ref$.zj, j = ref$.j, R = ref$.R, lit = ref$.lit, c = ref$.c, wait = ref$.wait, noop = ref$.noop, jspc = ref$.jspc;
be = com.hoplon.types;
guard = com.hoplon.guard;
cp = child_process;
os = require('os');
path = require('path');
homedir = os.homedir();
release = os.release();
re = /Microsoft/g;
if (release.match(re)) {
isWSL = true;
}
CONFIG_FILE_NAME = ".remotemon.yaml";
cmd_data = new optionParser();
cmd_data.addOption('h', 'help', null, 'help');
cmd_data.addOption('v', 'verbose', null, 'verbose');
cmd_data.addOption('V', 'version', null, 'version');
cmd_data.addOption('d', 'dry-run', null, 'dryRun');
cmd_data.addOption('w', 'watch-config-file', null, 'watch_config_file');
cmd_data.addOption('l', 'list', null, 'list');
cmd_data.addOption('m', 'auto-make-directory', null, 'auto_make_directory');
cmd_data.addOption('n', 'no-watch', null, 'no_watch');
cmd_data.addOption('s', 'silent', null, 'silent');
cmd_data.addOption('r', 'resume', null, 'resume');
cmd_data.addOption('c', 'cat', null, 'cat');
cmd_data.addOption('e', 'edit', null, 'edit');
cmd_data.addOption('p', 'project', null, 'project').argument('PROJECT');
question_init = function(){
var rl, out;
rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
out = {};
out.ask = function*(str){
return (yield new Promise(function(resolve, reject){
return rl.question(str, function(user){
return resolve(user);
});
}));
};
out.close = function(){
return rl.close();
};
return out;
};
if (!metadata.name) {
return false;
}
try {
rest = cmd_data.parse();
} catch (e$) {
E = e$;
print.optionParser(R.drop(2, process.argv));
return;
}
if (cmd_data.help.count() > 0) {
str = "" + metadata.name + " version " + metadata.version + "\n\noptions:\n\n -v --verbose more detail\n\n -vv much more detail\n\n -h --help display help message\n\n -V --version displays version number\n\n -d --dry-run perform a trial run without making any changes\n\n -w --watch-config-file restart on config file change\n\n -c --cat dump the output of the current " + CONFIG_FILE_NAME + " being used\n\n -cc same as -c but with comments\n\n -ccc show raw json for final process state\n\n -l --list list all user commands\n\n -ll show history of all commands called\n\n -m --auto-make-directory make remote directory if it doesn't exist ( with user permission )\n\n -mm ( with root permission )\n\n -n --no-watch force disable any and all watches\n\n -s --silent do not show " + metadata.name + " messages\n\n -e --edit make permanent edits to " + CONFIG_FILE_NAME + " values\n\n -p --project folder name to look for " + CONFIG_FILE_NAME + "\n\n -r --resume resume from failpoint if remotemon can pattern match command with older build failure\n\n ---- shorthands ----\n\n CF <-- for configuration file\n\nvalues for internal variables (using .var object) can be changed using '=' (similar to makefiles) :\n\n> " + metadata.name + " --verbose file=dist/main.js\n\n[ documentation ] @ [ " + metadata.homepage + " ]\n";
l(str);
return;
}
silent = cmd_data.silent.count();
edit = cmd_data.edit.count();
concatenate = cmd_data.cat.count();
if (cmd_data.version.count() > 0) {
l(c.er1("[" + metadata.name + "] version " + metadata.version));
return;
}
isvar = R.test(/^[\.\w\/]+=/);
check_if_number = function(str_data){
var isnum;
isnum = Number(str_data);
if (!deepEq$(isnum, NaN, '===')) {
return isnum;
}
return str_data;
};
vars = R.map(R.pipe(R.split('='), R.over(R.lensIndex(0), R.split("/")), R.over(R.lensIndex(1), check_if_number)))(
R.filter(isvar)(
rest));
args = R.reject(isvar, rest);
init = function*(){
var CONFIG_DIR, REMOTEMON_DIR, CONFIG_FILE, DEF_CONFIG_FILE, HIST_FILE, DEF_HIST_FILE, cmd, config_yaml_text, doc, service_dir, edit_config_file, q, str, ref$, str1, str2, lastchecktime, current_version_number, epoc, time_in_seconds, re, raw, ret, vn, corde, user_doc, prog_doc, fin_doc;
CONFIG_DIR = homedir + "/.config";
REMOTEMON_DIR = CONFIG_DIR + "/remotemon/";
CONFIG_FILE = REMOTEMON_DIR + "config.remotemon.yaml";
DEF_CONFIG_FILE = path.resolve(__dirname + '/../config.remotemon.yaml');
HIST_FILE = REMOTEMON_DIR + "hist.json";
DEF_HIST_FILE = path.resolve(__dirname + '/../hist.json');
if (!fs.existsSync(CONFIG_DIR)) {
exec("mkdir " + CONFIG_DIR);
}
if (!fs.existsSync(REMOTEMON_DIR)) {
exec("mkdir " + REMOTEMON_DIR);
}
if (!fs.existsSync(CONFIG_FILE)) {
cmd = "cp " + DEF_CONFIG_FILE + " " + REMOTEMON_DIR;
exec(cmd);
}
if (!fs.existsSync(HIST_FILE)) {
exec("cp " + DEF_HIST_FILE + " " + REMOTEMON_DIR);
}
config_yaml_text = R.toString(
fs.readFileSync(
CONFIG_FILE));
doc = yaml.parseDocument(config_yaml_text);
service_dir = doc.getIn(['service_directory']);
edit_config_file = false;
if (!service_dir) {
q = question_init();
str = c.er1("[" + metadata.name + "] service directory path : ");
service_dir = (yield* q.ask(str));
if (!((ref$ = R.last(service_dir)) === "/" || ref$ === "\\")) {
service_dir = service_dir + "/";
}
doc.setIn(['service_directory'], service_dir);
edit_config_file = true;
str1 = c.grey("service directory is set to " + c.warn(service_dir));
str2 = c.grey("can be changed anytime by editing ") + c.warn(CONFIG_FILE);
l(str1);
l(str2);
q.close();
} else {
if (!((ref$ = R.last(service_dir)) === "/" || ref$ === "\\")) {
service_dir = service_dir + "/";
doc.setIn(['service_directory'], service_dir);
edit_config_file = true;
}
}
lastchecktime = doc.getIn(['last_check_time']);
current_version_number = doc.getIn(['current_version_number']);
epoc = Date.now() / 1000;
time_in_seconds = 1 * 24 * 60 * 60;
re = /.*latest.*: (.*)/gm;
if (lastchecktime === 0) {
doc.setIn(['last_check_time'], epoc);
edit_config_file = true;
}
if (epoc - lastchecktime > time_in_seconds) {
raw = exec("npm view " + metadata.name);
ret = re.exec(raw);
vn = ret[1];
if (compare_version(vn, metadata.version) === 1) {
doc.setIn(['last_check_time'], epoc);
edit_config_file = true;
process.on('exit', function(){
var msg;
msg = "update available " + c.er2(metadata.version) + c.ok((" ➝ " + vn) + "\n\n" + c.grey("> sudo npm i -g remotemon \n" + c.grey("> sudo yarn global add remotemon \n" + c.grey("> sudo pnpm add -g remotemon"))));
return boxen.then(function(mo){
var boite;
boite = mo['default'];
return console.log(boite(msg, {
padding: 1,
borderColor: "green",
textAlignment: "left"
}));
});
});
}
}
corde = yaml.stringify(doc);
if (edit_config_file) {
wait(0, function(){
return fs.writeFile(CONFIG_FILE, corde, function(err){
return c.er1(err);
});
});
}
user_doc = doc.toJSON();
prog_doc = yaml.parse(
R.toString(
fs.readFileSync(
DEF_CONFIG_FILE)));
fin_doc = R.mergeLeft(user_doc, prog_doc);
fin_doc.HIST_FILE = HIST_FILE;
fin_doc.CONFIG_FILE = CONFIG_FILE;
return (yield fin_doc);
};
V = {};
defarg_main = be.undefnull.cont(function(){
var state;
state = arguments[arguments.length - 1];
return ['arr', state.cmdargs.length, []];
}).alt(be.arr.cont(function(arr){
var state, len;
state = arguments[arguments.length - 1];
len = R.max(arr.length, state.cmdargs.length);
return ['arr', len, arr];
})).alt(be.str.cont(function(str){
var state, len;
state = arguments[arguments.length - 1];
len = R.max(1, state.cmdargs.length);
return ['arr', len, [str]];
})).or(be(function(x){
return x === Infinity;
}).cont(function(){
var state, data;
state = arguments[arguments.length - 1];
data = state.cmdargs.join(" ");
return ['arr', 1, [data]];
})).alt(be.int.pos.cont(function(num){
var state, len;
state = arguments[arguments.length - 1];
len = R.max(num, state.cmdargs.length);
return ['req', len, []];
})).err([':defarg.type', 'is not of type array / str / int.pos']);
V.defarg = defarg_main.cont(function(data){
var state, __, len, list;
state = arguments[arguments.length - 1];
__ = data[0], len = data[1], list = data[2];
data[2] = mergeArray(len, data[2], state.cmdargs);
return data;
}).and(function(impdefarg){
var info, type, len, list;
info = arguments[arguments.length - 1];
type = impdefarg[0], len = impdefarg[1], list = impdefarg[2];
if (type === 'req' && len > list.length) {
return [false, [':defarg.req', len]];
}
return true;
}).err(function(E){
var info, type, msg, path;
info = arguments[arguments.length - 1];
type = E[0], msg = E[1];
switch (type) {
case ':defarg.req':
return print.defarg_req(msg, info.cmdname + " ");
case ':defarg.type':
// fallthrough
default:
path = [info.cmdname, 'defarg'];
return print.basicError(msg, path, info.configfile);
}
});
inpwd_str = be.str.and(function(s){
var info, serv_dir, fpath;
info = arguments[arguments.length - 1];
serv_dir = info.serv_dir;
switch (s[0]) {
case '/':
fpath = s;
break;
case '.':
fpath = path.resolve(info.fsp, s);
break;
default:
fpath = path.resolve(info.serv_dir + s);
}
if (!fs.existsSync(fpath)) {
return {
error: true,
message: [':no_file', fpath]
};
} else {
return {
'continue': true,
value: fpath
};
}
});
V.inpwd_core = be.bool.cont(function(bool){
var fsp;
fsp = arguments[arguments.length - 1].fsp;
switch (bool) {
case true:
return process.cwd();
case false:
return fsp;
}
}).or(inpwd_str).or(be.undef.cont(function(s, g){
return g;
})).err(function(message){
var data, ref$, type, val;
data = arguments[arguments.length - 1];
ref$ = be.flatro(message)[0], type = ref$[0], val = ref$[1];
switch (type) {
case ':no_file':
print.file_does_not_exists(val, data);
break;
default:
print.basicError(val, data.path, data.filename);
}
throw SERR;
});
V.inpwd = be.any.tap(function(){}).and(V.inpwd_core).wrap();
san_arr = be.arr.fix(function(){
return [];
});
san_user_script = function(lin){
var todisp, toexit;
lin = rm_empty_lines(lin);
todisp = R.join('\n')(R.init(lin));
toexit = R.last(lin);
return [todisp, toexit];
};
run_script = function(str, inpwd, project, path){
var lines, sp, interpreter, script, cmd, stdin, sortir, err_msg, user_lines, ref$, to_disp, to_exit;
lines = str.split('\n');
sp = lines[0].split(" ");
interpreter = sp[sp.length - 1];
lines.shift();
script = lines.join("\n");
cmd = script.replace(/"/g, '\\"');
stdin = interpreter + " <<<\"" + cmd + "\"";
sortir = cp.spawnSync(stdin, [], {
shell: 'bash',
windowsVerbatimArguments: true,
cwd: inpwd
});
err_msg = sortir.stderr.toString();
if (err_msg.length > 0) {
print.error_in_user_script(err_msg, path);
throw SERR;
}
user_lines = sortir.stdout.toString().split("\n");
ref$ = san_user_script(user_lines), to_disp = ref$[0], to_exit = ref$[1];
if (!(to_disp === '')) {
console.log(to_disp);
}
return to_exit;
};
x$ = gs_path = {};
y$ = x$.js = {};
y$.loop = null;
y$.main = null;
z$ = x$.yl = {};
z$.loop = null;
z$.main = null;
x$.loop = null;
x$.main = null;
x$.yaml = null;
x$.shebang = /!#|#!/;
x$.tampax = /\${.*}/;
x$.linebreak = /\n/;
get_str_type = function(str){
var has_shebang, has_expansion, has_linebreak, is_script, is_tampax;
has_shebang = str.match(gs_path.shebang);
has_expansion = str.match(gs_path.tampax);
has_linebreak = str.match(gs_path.linebreak);
is_script = false;
is_tampax = false;
if (has_shebang && has_linebreak) {
is_script = true;
}
if (has_expansion) {
is_tampax = true;
}
return [is_script, is_tampax];
};
handle_path_dot = {};
handle_path_dot.save = be.str.tap(function(index, path, hist){
if (index.match("\\.")) {
return hist.dotpath.push(arrayFrom$(path).concat([index]));
}
}).alt(be.num).cont(function(index, path){
return path.concat(index);
}).wrap();
handle_path_dot.save_matrix = function(path, yIndex, hist){
var i$, len$, xIndex, each, results$ = [];
for (i$ = 0, len$ = path.length; i$ < len$; ++i$) {
xIndex = i$;
each = path[i$];
if (R.type(each) === 'String') {
if (each.match("\\.")) {
results$.push(hist.dotmatrix.push([yIndex, xIndex]));
}
}
}
return results$;
};
symbol_script = Symbol('is_script');
gs_path.js.loop = function(unknown, path, ref){
var w, index, value, npath, i$, len$, spath, ref$, is_script, is_tampax, cmdname, index_name, results$ = [], results1$ = [];
w = R.type(unknown);
if (w === 'Object') {
for (index in unknown) {
value = unknown[index];
npath = handle_path_dot.save(index, path, ref);
results$.push(gs_path.js.loop(value, npath, ref));
}
return results$;
} else if (w === 'Array') {
for (i$ = 0, len$ = unknown.length; i$ < len$; ++i$) {
index = i$;
value = unknown[i$];
npath = handle_path_dot.save(index, path, ref);
results1$.push(gs_path.js.loop(value, npath, ref));
}
return results1$;
} else {
spath = path.join(".");
if (!global_data.selected_keys.set.has(path[0]) && !(path[0] === ref.cmdname)) {
return;
}
if (path[0] === 'defarg' || path[1] === 'defarg') {
return;
}
ref.all[spath] = unknown;
handle_path_dot.save_matrix(path, ref.pall.length, ref);
ref.pall.push(path);
if (w === 'String') {
ref$ = get_str_type(unknown), is_script = ref$[0], is_tampax = ref$[1];
if (is_script) {
ref.script_all.push(spath);
ref.script[spath] = path;
unknown = symbol_script;
}
if (is_tampax) {
ref.tampax[spath] = void 8;
ref.tampax_all.push(path);
}
}
if (path[0] === 'var') {
ref.glovar[R.drop(1, path).join(".")] = unknown;
}
if (path[1] === 'var') {
cmdname = path[0];
index_name = R.join(".")(
R.drop(2, path));
return ref.cmdvar[index_name] = unknown;
}
}
};
gs_path.yl.loop = be(function(obj){
var a;
a = yaml.isMap(obj.value);
return a;
}).tap(function(obj, type, path, ref){
var items, i$, len$, each, p, results$ = [];
items = obj.value.items;
for (i$ = 0, len$ = items.length; i$ < len$; ++i$) {
each = items[i$];
p = arrayFrom$(path).concat([each.key.value]);
results$.push(gs_path.yl.loop.auth(each, 'map', p, ref));
}
return results$;
}).or(be(function(obj){
var b;
b = yaml.isSeq(obj.value);
return b;
}).tap(function(obj, type, path, ref){
var items, i$, len$, index, each, p, results$ = [];
items = obj.value.items;
for (i$ = 0, len$ = items.length; i$ < len$; ++i$) {
index = i$;
each = items[i$];
p = arrayFrom$(path).concat([index]);
results$.push(gs_path.yl.loop.auth(each, 'seq', p, ref));
}
return results$;
})).or(be.tap(function(obj, type, path, ref){
var sortir;
switch (type) {
case 'map':
if (yaml.isAlias(obj.value)) {
sortir = {
alias: obj.value.source,
path: path
};
ref.alias.push(sortir);
}
if (obj.value.anchor) {
return ref.anchor[obj.value.anchor] = path.join('.');
}
break;
case 'seq':
if (obj.anchor) {
return ref.anchor[obj.anchor] = path.join('.');
}
}
}));
gs_path.js.main = function(obj, cmdname){
var x$, hist;
x$ = hist = {};
x$.script_all = [];
x$.tampax = {};
x$.tampax_all = [];
x$.dotpath = [];
x$.dotmatrix = [];
x$.all = {};
x$.pall = [];
x$.glovar = {};
x$.cmdvar = {};
x$.script = {};
x$.cmdname = cmdname;
gs_path.js.loop(obj, [], hist);
return hist;
};
gs_path.yl.main = function(obj){
var x$, hist, ym, input;
x$ = hist = {};
x$.alias = [];
x$.anchor = {};
ym = obj.contents;
input = {};
input.value = obj.contents;
gs_path.yl.loop.auth(input, 'map', [], hist);
return hist;
};
gs_path.yl.find_cmd_name = function(contents){
var all_top_values, i$, ref$, len$, each, only_cmds;
all_top_values = [];
for (i$ = 0, len$ = (ref$ = contents.items).length; i$ < len$; ++i$) {
each = ref$[i$];
all_top_values.push(each.key.value);
}
only_cmds = R.difference(all_top_values, global_data.selected_keys.arr);
return only_cmds;
};
rm_merge_key = function(data){
var clean, i$, ref$, len$, each, path, sortir, alias, p;
clean = [];
for (i$ = 0, len$ = (ref$ = data.alias).length; i$ < len$; ++i$) {
each = ref$[i$];
path = each.path;
if (R.last(path) === '<<') {
continue;
}
if (path[0] === 'var') {
continue;
}
if (path[1] === 'var') {
continue;
}
clean.push(each);
}
sortir = {};
for (i$ = 0, len$ = clean.length; i$ < len$; ++i$) {
ref$ = clean[i$], alias = ref$.alias, path = ref$.path;
p = path.join('.');
sortir[p] = alias;
}
return sortir;
};
san_defarg = function(js, info){
return function(path){
var dirty_defarg, defarg, arr;
dirty_defarg = R.path(path, js);
defarg = V.defarg.auth(dirty_defarg, info);
if (defarg.error) {
throw SERR;
}
arr = defarg.value[2];
return arr;
};
};
update_defarg = function(defarg, type){
var p, i$, ref$, len$, index, str, ref1$, is_script, is_tampax, path;
p = type.join('.');
for (i$ = 0, len$ = (ref$ = defarg[p]).length; i$ < len$; ++i$) {
index = i$;
str = ref$[i$];
if (R.type(str) !== 'String') {
continue;
}
ref1$ = get_str_type(str), is_script = ref1$[0], is_tampax = ref1$[1];
if (is_script) {
path = p + '.' + index;
defarg.script_all.push(path);
defarg.script[path] = arrayFrom$(type).concat([index]);
}
if (is_tampax) {
defarg.tampax_all.push(arrayFrom$(type).concat([index]));
}
}
};
yaml_parse = function(doc, info){
var js, E;
try {
doc.setSchema('1.1');
js = doc.toJS();
return js;
} catch (e$) {
E = e$;
print.yaml_parse_fail(String(E), info);
throw SERR;
}
};
re_curly = /\${([\w\.]*)}/gm;
get_curly = function(str){
var found, sortir;
found = true;
sortir = [];
while (found) {
found = re_curly.exec(str);
if (found) {
sortir.push(found[1]);
}
}
return sortir;
};
tampax_abs = {};
clear = {};
merge_ref_defarg = function(defarg, ref){
var nset, n_script_all, index, ref$, value, i$, len$, str, path, p;
ref.project = defarg.project;
ref.localpwd = defarg.localpwd;
ref.globalpwd = defarg.globalpwd;
nset = R.merge(ref.script, defarg.script);
ref.script = nset;
n_script_all = arrayFrom$(defarg.script_all).concat(arrayFrom$(ref.script_all));
ref.script_all = n_script_all;
for (index in ref$ = defarg.tampax) {
value = ref$[index];
ref.tampax[index] = value;
}
for (i$ = 0, len$ = (ref$ = defarg.defarg).length; i$ < len$; ++i$) {
index = i$;
str = ref$[i$];
ref.all['defarg.' + index] = str;
path = ['defarg', index];
ref.pall.push(path);
}
if (ref.cmdname) {
p = ref.cmdname + '.defarg';
for (i$ = 0, len$ = (ref$ = defarg[p]).length; i$ < len$; ++i$) {
index = i$;
str = ref$[i$];
ref.all[p + '.' + index] = str;
path = [ref.cmdname, 'defarg', index];
handle_path_dot.save_matrix(path, ref.pall.length, ref);
ref.pall.push(path);
}
return ref.pwd = ref.localpwd;
} else {
return ref.pwd = ref.globalpwd;
}
};
clear.tampax = function(name, ref, path){
var expansions, str, i$, len$, each, has_tampax, is_script, exists, save, istr;
expansions = ref.tampax[name];
str = ref.all[name];
for (i$ = 0, len$ = expansions.length; i$ < len$; ++i$) {
each = expansions[i$];
has_tampax = Boolean(ref.tampax[each]);
is_script = ref.script[each];
exists = ref.all[each];
if (is_script) {
save = "[" + each + ":script]";
} else if (has_tampax) {
if (!path.has(each)) {
istr = clear.tampax(each, ref, new Set(arrayFrom$(path).concat([each])));
} else {
istr = "[" + each + ":loop]";
}
save = istr;
} else if (exists) {
save = exists;
} else {
save = "[" + each + ":void]";
}
str = str.replace("${" + each + "}", save);
}
return str;
};
clear.tampax_fin = function(name, ref, path){
var expansion, str, i$, len$, each, has_tampax, exists, save;
expansion = ref.tampax[name];
str = ref.all[name];
for (i$ = 0, len$ = expansion.length; i$ < len$; ++i$) {
each = expansion[i$];
has_tampax = Boolean(ref.tampax[each]);
exists = ref.all[each];
if (has_tampax) {
if (!path.has(each)) {
save = clear.tampax(each, ref, new Set(arrayFrom$(path).concat([each])));
} else {
save = "[" + each + ":loop]";
}
} else if (exists) {
save = exists;
} else {
save = "[" + each + ":void]";
}
str = str.replace("${" + each + "}", save);
}
ref.all[name] = str;
};
clear.script = function(ref, defarg){
var script_all, i$, len$, each, has_tampax, exists, script_text, init, pwd, val, tampax, results$ = [];
script_all = ref.script_all;
for (i$ = 0, len$ = script_all.length; i$ < len$; ++i$) {
each = script_all[i$];
has_tampax = ref.tampax[each];
exists = ref.all[each];
if (has_tampax) {
script_text = clear.tampax(each, ref, new Set([each]));
} else {
script_text = exists;
}
init = ref.script[each][0];
if (init === ref.cmdname) {
pwd = ref.localpwd;
} else {
pwd = ref.globalpwd;
}
val = run_script(script_text, pwd, ref.project, each);
ref.all[each] = val;
ref.script[each] = void 8;
delete ref.tampax[each];
}
tampax = ref.tampax;
for (each in tampax) {
results$.push(clear.tampax_fin(each, ref, new Set([each])));
}
return results$;
};
tampax_abs.defarg = function(defarg, ref){
var local_path, i$, ref$, len$, each, varspace, link, num_link, loc, index, str, matches, allspace, rep, j$, len1$, I, found, rstr, ifnum;
local_path = ref.cmdname + ".defarg";
for (i$ = 0, len$ = (ref$ = defarg.tampax_all).length; i$ < len$; ++i$) {
each = ref$[i$];
switch (each[0]) {
case 'defarg':
varspace = ref.glovar;
link = "var.";
num_link = "defarg.";
loc = "defarg";
index = each[1];
break;
default:
varspace = ref.cmdvar;
link = ref.cmdname + ".var.";
num_link = ref.cmdname + ".defarg.";
loc = ref.cmdname + ".defarg";
index = each[2];
}
str = defarg[local_path][index];
matches = get_curly(str);
allspace = ref.all;
rep = [];
for (j$ = 0, len1$ = matches.length; j$ < len1$; ++j$) {
I = matches[j$];
found = varspace[I];
if (found) {
rstr = link + I;
rep.push(rstr);
str = str.replace("${" + I + "}", "${" + rstr + "}");
defarg[loc][index] = str;
} else {
found = allspace[I];
rstr = I;
ifnum = parseInt(I);
if (!found) {
if (ifnum === 0 || ifnum) {
rstr = num_link + ifnum;
str = str.replace("${" + I + "}", "${" + rstr + "}");
defarg[loc][index] = str;
} else if (loc === local_path) {
found = ref.glovar[I];
if (found) {
rstr = "var." + I;
str = str.replace("${" + I + "}", "${" + rstr + "}");
defarg[loc][index] = str;
}
}
}
rep.push(rstr);
}
}
defarg.tampax[each.join('.')] = rep;
}
return ref$ = defarg.tampax_all, delete defarg.tampax_all, ref$;
};
tampax_abs.ref = function(defarg, ref){
var cmdname, i$, ref$, len$, each, loc, index, varspace, link, num_link, p, str, matches, allspace, rep, j$, len1$, I, found, rstr, ifnum;
cmdname = ref.cmdname;
for (i$ = 0, len$ = (ref$ = ref.tampax_all).length; i$ < len$; ++i$) {
each = ref$[i$];
loc = each[0], index = each[1];
switch (loc) {
case cmdname:
varspace = ref.cmdvar;
link = ref.cmdname + '.var.';
num_link = ref.cmdname + ".defarg.";
break;
default:
varspace = ref.glovar;
link = 'var.';
num_link = "defarg.";
}
p = each.join(".");
str = ref.all[p];
matches = get_curly(str);
allspace = ref.all;
rep = [];
for (j$ = 0, len1$ = matches.length; j$ < len1$; ++j$) {
I = matches[j$];
found = varspace[I];
if (found) {
rstr = link + I;
rep.push(rstr);
str = str.replace("${" + I + "}", "${" + rstr + "}");
ref.all[p] = str;
} else {
found = allspace[I];
rstr = I;
ifnum = parseInt(I);
if (!found) {
if (ifnum === 0 || ifnum) {
rstr = num_link + ifnum;
str = str.replace("${" + I + "}", "${" + rstr + "}");
ref.all[p] = str;
} else if (loc === cmdname) {
found = ref.glovar[I];
if (found) {
rstr = "var." + I;
str = str.replace("${" + I + "}", "${" + rstr + "}");
ref.all[p] = str;
}
}
}
rep.push(rstr);
}
}
ref.tampax[p] = rep;
}
return ref$ = ref.tampax_all, delete ref.tampax_all, ref$;
};
check_if_circular_ref = function(defarg, ref){
var each, ref$, item, i$, len$, I, loc, matches;
for (each in ref$ = defarg.tampax) {
item = ref$[each];
for (i$ = 0, len$ = item.length; i$ < len$; ++i$) {
I = item[i$];
if (I === each) {
print.circular_ref(I);
throw SERR;
}
}
}
for (loc in ref$ = ref.tampax) {
matches = ref$[loc];
for (i$ = 0, len$ = matches.length; i$ < len$; ++i$) {
each = matches[i$];
if (loc === each) {
print.circular_ref(loc);
throw SERR;
}
}
}
};
replace_dot = {};
replace_dot.encode = function(ref){
var i$, ref$, len$, ref1$, yAxis, xAxis, path, str, nstr, oldpath, npath, val, results$ = [];
for (i$ = 0, len$ = (ref$ = ref.dotmatrix).length; i$ < len$; ++i$) {
ref1$ = ref$[i$], yAxis = ref1$[0], xAxis = ref1$[1];
path = ref.pall[yAxis];
str = path[xAxis];
nstr = R.join(": ")(
R.split(".")(
str));
oldpath = path.join('.');
path[xAxis] = nstr;
npath = path.join('.');
val = ref.all[oldpath];
delete ref.all[oldpath];
results$.push(ref.all[npath] = val);
}
return results$;
};
pathops = guard.ar(2, function(path, obj){
return pathops(path, obj, '', 'del');
}).ar(3, function(path, obj, str){
return pathops(path, obj, str, 'mod');
}).def(function(path, obj, str, type){
var ou, lastname, i$, to$, I;
ou = obj;
lastname = path[path.length - 1];
for (i$ = 0, to$ = path.length - 1; i$ < to$; ++i$) {
I = i$;
ou = ou[path[I]];
}
switch (type) {
case 'del':
delete ou[lastname];
break;
case 'mod':
ou[lastname] = str;
}
return obj;
});
replace_dot.decode = function(ref, js){
var i$, ref$, len$, each, ref1$, newpath, last, nstr, val;
for (i$ = 0, len$ = (ref$ = ref.dotpath).length; i$ < len$; ++i$) {
each = ref$[i$];
ref1$ = R.splitAt(-1, each), newpath = ref1$[0], last = ref1$[1];
nstr = R.join(": ")(
R.split(".")(
last[0]));
newpath.push(nstr);
val = R.path(newpath, js);
pathops(each, js, val);
pathops(newpath, js);
}
return js;
};
modyaml = function*(info){
var configfile, data, doc, allcmdnames, cmd_equ_func, is_cmd, nominal_path, cmdname, i$, ref$, len$, ref1$, key, value, p_cmdvar, p_empty, init, p, alt_p, v_path, d_path, js_all, js, sk, index, ref, doro, defarg, project, sd, serv_dir, ipd, global_inpwd, ipd2, ipd3, inpwd, a_path, cd, clean_data;
configfile = info.configfile;
data = R.toString(
fs.readFileSync(
configfile));
doc = parseDoc(data, info);
allcmdnames = gs_path.yl.find_cmd_name(doc.contents);
cmd_equ_func = R.equals(
args[0]);
is_cmd = R.find(cmd_equ_func, allcmdnames);
if (is_cmd) {
info.cmdname = args[0];
info.cmdargs = R.drop(1, args);
} else {
info.cmdname = void 8;
info.cmdargs = args;
}
nominal_path = null;
cmdname = info.cmdname;
if (cmdname === undefined) {
for (i$ = 0, len$ = (ref$ = info.vars).length; i$ < len$; ++i$) {
ref1$ = ref$[i$], key = ref1$[0], value = ref1$[1];
if (key[0] === 'var') {
key.shift();
}
doc.setIn(['var'].concat(arrayFrom$(key)), value);
}
nominal_path = [];
} else {
p_cmdvar = [cmdname, 'var'];
p_empty = [];
for (i$ = 0, len$ = (ref$ = info.vars).length; i$ < len$; ++i$) {
ref1$ = ref$[i$], key = ref1$[0], value = ref1$[1];
if (key[0] === 'var') {
init = p_empty;
p = key;
} else {
init = p_cmdvar;
p = arrayFrom$(init).concat(arrayFrom$(key));
alt_p = ['var'].concat(arrayFrom$(key));
if (doc.getIn(p) === undefined && doc.getIn(alt_p)) {
p = alt_p;
}
}
doc.setIn(p, value);
}
nominal_path = [cmdname];
}
v_path = arrayFrom$(nominal_path).concat(['var']);
d_path = arrayFrom$(nominal_path).concat(['defarg']);
js_all = yaml_parse(doc, info);
js = {};
if (info.options.edit || info.options.list) {
return [js_all, doc];
}
sk = global_data.selected_keys.set;
for (index in js_all) {
value = js_all[index];
if (sk.has(index) || index === cmdname) {
js[index] = value;
}
}
ref = gs_path.js.main(js, cmdname);
for (index in ref$ = ref.script) {
doro = ref$[index];
if (!(((ref1$ = doro[0]) === 'var' || ref1$ === 'defarg') || ((ref1$ = doro[1]) === 'var' || ref1$ === 'defarg'))) {
print.script_in_wrong_place(index);
throw SERR;
}
}
defarg = {};
project = info.options.project;
defarg.project = project;
defarg.defarg = null;
if (ref.cmdname) {
defarg[ref.cmdname + '.defarg'] = {};
}
defarg.localpwd = null;
defarg.globalpwd = null;
defarg.script_all = [];
defarg.script = {};
defarg.tampax = {};
defarg.tampax_all = [];
sd = san_defarg(js, info);
defarg.defarg = sd(['defarg']);
serv_dir = info.options.service_directory;
ipd = {
filename: info.options.global_config_file,
path: ['pwd'],
fsp: project,
serv_dir: serv_dir
};
global_inpwd = V.inpwd(info.options.pwd, project, ipd);
ipd2 = R.merge(ipd, {
filename: configfile
});
defarg.globalpwd = V.inpwd(js.pwd, global_inpwd, ipd2);
if (cmdname) {
if (global_data.selected_keys.set.has(cmdname)) {
print.in_selected_key(cmdname, info.cmdline);
throw SERR;
}
if (!js[cmdname]) {
print.could_not_find_custom_cmd(cmdname, info);
throw SERR;
}
ipd3 = R.merge(ipd2, {
path: [cmdname, 'pwd']
});
inpwd = V.inpwd(js[cmdname].pwd, defarg.globalpwd, ipd3);
defarg.localpwd = inpwd;
a_path = [cmdname, 'defarg'];
p = cmdname + '.defarg';
defarg[p] = sd(a_path);
update_defarg(defarg, a_path);
} else {
update_defarg(defarg, ['defarg']);
}
tampax_abs.defarg(defarg, ref);
tampax_abs.ref(defarg, ref);
delete ref.glovar;
delete ref.cmdvar;
check_if_circular_ref(defarg, ref);
merge_ref_defarg(defarg, ref);
clear.script(ref, defarg);
replace_dot.encode(ref);
cd = com.hoplon.utils.flat.unflatten(ref.all);
clean_data = replace_dot.decode(ref, cd);
clean_data.pwd = defarg.globalpwd;
if (cmdname) {
clean_data[cmdname].pwd = defarg.localpwd;
}
return [clean_data, doc];
};
parseDoc = function(data, info){
var doc, error;
doc = yaml.parseDocument(data);
error = doc.errors[0];
if (error) {
print.yaml_parse_fail(error.toString(), info);
throw SERR;
}
if (!doc.contents) {
print.yaml_parse_fail('yaml file is empty.\n', info);
throw SERR;
}
return doc;
};
show = R.tap(function(ob){
console.log([ob]);
});
nPromise = function(f){
return new Promise(f);
};
rmdef = R.reject(function(x){
return global_data.selected_keys.set.has(x);
});
only_str = be.str.cont(function(str){
return " - " + str;
}).or(be.arr.cont(function(arr){
var fin, i$, len$, I;
fin = "";
for (i$ = 0, len$ = arr.length; i$ < len$; ++i$) {
I = arr[i$];
fin += "\n - " + I;
}
return fin;
})).fix("").wrap();
function exec_list_option(yjson, info){
var keys, user_ones, color, i$, to$, I, name, des, cc, results$ = [];
l(lit(['> FILE ', info.configfile], [c.er2, c.grey]));
keys = Object.keys(yjson);
user_ones = rmdef(keys);
if (user_ones.length === 0) {
l(lit([" --- ", "< EMPTY USER CMD >", " ---"], [c.pink, c.er2, c.pink]));
}
color = [c.warn, c.er1];
for (i$ = 0, to$ = user_ones.length; i$ < to$; ++i$) {
I = i$;
name = user_ones[I];
des = only_str(yjson[name].description);
cc = color[I % 2];
results$.push(l(lit([" • ", name, des], [cc, cc, c.grey])));
}
return results$;
}
function exec_cat_option(yaml_object, concat_count, info){
var yaml_text, hash_first, lines, interm, i$, len$, I, text;
yaml_text = yaml_object.toString();
hash_first = RegExp('^#');
lines = yaml_text.split("\n");
interm = [];
switch (concat_count) {
case 1:
for (i$ = 0, len$ = lines.length; i$ < len$; ++i$) {
I = lines[i$];
if (!hash_first.exec(I) && I.length !== 0) {
interm.push(I);
}
}
break;
case 2:
interm = lines;
}
text = interm.join('\n');
return l(info.libs.emphasize.highlightAuto(text).value);
}
SERR = Symbol('error');
OK = Symbol('ok');
tampax_parse = function(yaml_text, cmdargs, filename){
return nPromise(function(resolve, reject){
return tampax.yamlParseString(yaml_text, cmdargs, function(err, rawjson){
if (err) {
err = err.split("\n")[0];
print.failed_in_tampax_parsing(filename, err);
resolve(SERR);
return;
}
return resolve(rawjson);
});
});
};
mergeArray = function(deflength, def, arr){
var tail, len, rest, fin, i$, I;
tail = def[def.length - 1];
if (tail === Infinity) {
len = def.length - 1;
rest = arr.splice(len, arr.length);
if (rest.length > 0) {
rest = [rest.join(" ")];
}
arr = arrayFrom$(arr).concat(arrayFrom$(rest));
def[len] = '';
}
fin = [];
for (i$ = 0; i$ < deflength; ++i$) {
I = i$;
if (arr[I] === undefined && def[I] === undefined) {
break;
} else if (arr[I] === undefined) {
fin[I] = def[I];
} else {
fin[I] = arr[I];
}
}
return fin;
};
unu = be.undefnull.cont(void 8);
V.rsl = be.arr.cont(R.flatten).map(be.str.or(be.obj.and(function(obj){
var keys;
keys = Object.keys(obj);
switch (keys.length) {
case 0:
return [false, [':ob_in_str_list', 'empty_object']];
default:
return [false, [':ob_in_str_list', 'object']];
}
})).or(unu)).alt(be.str.cont(function(x){
return [x];
})).err(function(all){
var sortie, type, msg;
sortie = be.flatro(all);
type = sortie[0], msg = sortie[1];
switch (type) {
case ':ob_in_str_list':
return msg;
default:
return "not string or string list.";
}
}).cont(R.without([void 8]));
V.strlist = function(F){
return V.rsl.or(be.undefnull.cont(F));
};
V.strlist.empty = V.strlist(function(){
return [];
});
V.strlist.dot = V.strlist(function(){
return ["."];
});
V.strlist['false'] = V.strlist(false);
is_false = function(x){
if (x === false) {
return true;
}
return [false, 'not false'];
};
is_true = function(x){
if (x === true) {
return true;
}
return [false, 'not true'];
};
V.isFalse = be(is_false);
V.isTrue = be(is_true);
ifTrue = function(field){
return function(){
var state, defecto_user, defecto_conf;
state = arguments[arguments.length - 1];
defecto_user = state.origin[field];
defecto_conf = state.info.options[field];
if (R.type(defecto_user) === 'Array' && defecto_user.length > 0) {
return defecto_user;
}
if (R.type(defecto_conf) === 'Array' && defecto_conf.length > 0) {
return defecto_conf;
}
switch (field) {
case 'watch':
return ["."];
case 'ignore':
return [];
}
};
};
V.watch = {};
V.watch.main = V.rsl.or(be.undefnull.alt(V.isFalse).cont(function(){
return [];
}));
V.watch.def = V.watch.main.or(V.isTrue.cont(function(){
var state;
state = arguments[arguments.length - 1];
return state.info.options.watch;
}));
V.watch.user = V.watch.main.or(V.isTrue.cont(ifTrue('watch')));
V.ignore = {};
V.ignore.def = V.watch.main.or(V.isTrue.cont(function(){
var state;
state = arguments[arguments.length - 1];
return state.info.options.ignore;
}));
V.ignore.user = V.watch.main.or(V.isTrue.cont(ifTrue('ignore')));
V.execlist = V.strlist.empty.cont(function(strlist){
var sortir, i$, len$, str, nstr;
sortir = [];
for (i$ = 0, len$ = strlist.length; i$ < len$; ++i$) {
str = strlist[i$];
nstr = str.replace(/'/g, "'''");
sortir.push(nstr);
}
return sortir;
});
V.arr_str = be.arr.map(be.str).or(be.str.cont(function(str){
return [str];
}));
V.arr_str_empty = V.arr_str.or(be.undefnull.cont(function(){
return [];
}));
V.rsync = {};
V.rsync.throw_if_error = function(data){
var rsync, ref$, msg, index, tosend, i$, len$, each, path;
rsync = data.rsync;
if (rsync === false) {
return true;
}
if (rsync.error) {
ref$ = rsync.error, msg = ref$[0], index = ref$[1];
tosend = [false, [':rsync', msg], ['rsync'].concat(arrayFrom$(index))];
return tosend;
}
for (i$ = 0, len$ = rsync.length; i$ < len$; ++i$) {
index = i$;
each = rsync[i$];
if (R.type(each.des) !== 'String') {
msg = [".des is not defined. maybe remotefold is not defined."];
path = R.slice(1, -1, arguments);
tosend = [false, [':rsync', ['uno', msg]], ['rsync', index, 'des']];
return tosend;
}
}
return true;
};
san_remotefold = function(data, cmdname){
var st;
if (R.type(data.remotefold) !== 'String') {
st = {};
st.error = [['def', "remotefold is undefined (unable to substitute .des in rsync).", [cmdname, 'remotefold']], []];
return [SERR, st];
}
return [OK];
};
rsync_arr2obj = function(data, cmdname, remotefold){
var fin, error, list, i$, len$, index, I, keys, k, val, ret, ref$;
fin = {
str: [],
obnormal: [],
obarr: {},
des: null,
src: [],
error: false
};
error = [];
list = R.flatten(data);
for (i$ = 0, len$ = list.length; i$ < len$; ++i$) {
index = i$;
I = list[i$];
switch (R.type(I)) {
case 'String':
if (!global_data.rsync.bool.has(I)) {
error.push(['duo', [I, "not a valid boolean rsync option."]], [index]);
fin.error = error;
return fin;
}
fin.str.push(I);
break;
case 'Object':
keys = Object.keys(I);
switch (keys.length) {
case 0:
error.push(['uno', ["empty object without any attribute"]], [index]);
fin.error = error;
return fin;
case 1:
break;
default:
error.push(['uno', ["object can only have singular attribute."]], [index]);
fin.error = error;
return fin;
}
k = keys[0];
if (!(global_data.rsync.compound.has(k) || (k === 'src' || k === 'des'))) {
error.push(['duo', [k, " not a valid compound rsync option."]], [index]);
fin.error = error;
return fin;
}
val = I[k];
if (k === 'des') {
if (!(R.type(val) === 'String')) {
error.push(['duo', ['des', "has to be string type."]], [index]);
fin.error = error;
return fin;
}
if (fin.des) {
error.push(['duo', ['des', " there can't be multiple remote folders as destination."]], [index]);
fin.error = error;
return fin;
}
fin.des = val;
} else if (k === 'src' || global_data.rsync.filter.has(k)) {
ret = V.arr_str_empty.auth(val);
if (ret.error) {
error.push(['duo', [k, "can only be a list of string or just string."]], [index].concat(arrayFrom$(ret.path)));
fin.error = error;
return fin;
}
if (k === 'src') {
fin.src.push(ret.value);
} else {
if (fin.obarr[k] === undefined) {
fin.obarr[k] = [];
}
(ref$ = fin.obarr[k]).push.apply(ref$, ret.value);
}
} else {
switch (R.type(val)) {
case 'String':
case 'Number':
fin.obnormal.push([k, val.replace(/'/g, "'\\''")]);
break;
case 'Undefined':
case 'Null':
break;
default:
error.push(['duo', [k, "can only be a string (or number)."]], [index]);
fin.error = error;
return fin;
}
}
break;
default:
error.push(['uno', ["not valid rsync option."]], [index]);
fin.error = error;
return fin;
}
}
fin.src = R.flatten(fin.src);
if (!fin.des) {
fin.des = remotefold;
}
if (fin.src.length === 0) {
fin.src.push(".");
}
return fin;
};
ifrsh = function(arg$){
var key;
key = arg$[0];
return key === 'rsh';
};
organize_rsync = function(data, cmdname){
var state, rsync, remotefold, add, fin, i$, to$, I, st, ref$, len$, obnormal, ssh;
state = arguments[arguments.length - 1];
rsync = data.rsync, remotefold = data.remotefold;
if (rsync === false) {
return data;
}
if (rsync === true) {
add = [{
des: remotefold
}];
rsync = [state.info.options.rsync.concat(add)];
}
fin = [];
for (i$ = 0, to$ = rsync.length; i$ < to$; ++i$) {
I = i$;
st = rsync_arr2obj(rsync[I], cmdname, remotefold);
if (st === SERR) {
return data;
}
if (st.error) {
st.error[1].unshift(I);
data.rsync = st;
return data;
} else {
fin.push(st);
}
}
data.rsync = fin;
for (i$ = 0, len$ = (ref$ = data.rsync).length; i$ < len$; ++i$) {
obnormal = ref$[i$].obnormal;
if (!R.find(ifrsh, obnormal)) {
if (data.ssh) {
ssh = [['rsh', "ssh " + data.ssh]];
} else if (state.origin.ssh) {
ssh = [['rsh', "ssh " + state.origin.ssh.option]];
} else {
ssh = [];
}
obnormal.push.apply(obnormal, ssh);
}
}
return data;
};
V.rsync.init = be.bool.or(be.undefnull.cont(false)).or(be.arr.map(be.arr).err(function(msg, key){
switch (key) {
case undefined:
return [':rsync_top', 'not array'];
default:
return ['not_array_of_array', key];
}
})).or(be.arr.cont(function(a){
return [a];
}));
dangling_colon = be.arr.cont(function(arr){
var sortir, re, i$, len$, str;
sortir = "";
re = /;\s*/;
for (i$ = 0, len$ = arr.length; i$ < len$; ++i$) {
str = arr[i$];
str = str.replace(re, ";");
if (!(str[str.length - 1] === ";")) {
str = str + ";";
}
sortir += str;
}
return sortir;
}).or(be.str).wrap();
V.ssh = be.obj.on('option', be.str.or(unu)).on('startwith', be.arr.map(be.str).or(be.undefnull.cont(function(){
return [];
}))).alt(be.str.cont(function(str){
return {
option: str,
startwith: []
};
})).alt(be.undefnull.cont(function(){
return {
option: void 8,
startwith: []
};
}));
V.def_ssh = V.ssh.cont(function(ob){
var state, origin, tsel;
state = arguments[arguments.length - 1];
origin = state.origin;
if (ob.startwith.length === 0) {
tsel = "cd " + origin.remotefold + ";";
ob.startwith.push(tsel);
}
if (ob.option === void 8) {
ob.option = state.info.options.ssh.option;
}
ob.startwith = dangling_colon(ob.startwith);
return ob;
});
V.user_ssh = V.ssh;
handle_ssh = function(user, def){
var path, tsel;
if (user.ssh.startwith.length === 0) {
if (user.remotefold) {
path = san_path(user.remotefold);
tsel = "cd " + path;
user.ssh.startwith.push(tsel);
} else {
user.ssh.startwith = def.ssh.startwith;
}
}
user.ssh.startwith = dangling_colon(user.ssh.startwith);
if (!user.ssh.option) {
user.ssh.option = def.ssh.option;
}
};
V.def_vars = be.obj.or(be.undefnull.cont(function(){
return {};
}));
V.user_vars = V.def_vars.cont(function(ob){
var state, out;
state = arguments[arguments.length - 1];
out = R.mergeDeepLeft(ob, state.origin['var']);
return out;
});
str_to_num = be.str.cont(function(str){
return Number(str);
}).and(be.int.pos).or(be.int.pos).err('not number');
V.defarg_required = str_to_num.or(be.undefnull.cont(function(obj){
var state, defarg, max_null, i$, len$, I;
state = arguments[arguments.length - 1];
if (arguments.length === 4) {
defarg = state.origin[arguments[2]].defarg;
} else if (arguments.length === 3) {
defarg = state.origin.defarg;
}
if (!defarg) {
defarg = [];
}
max_null = 0;
for (i$ = 0, len$ = defarg.length; i$ < len$; ++i$) {
I = defarg[i$];
if (I === null) {
max_null += 1;
} else {
break;
}
}
return max_null;
}));
V.user = be.obj.err("custom user defined task, has to be object.").or(be.undefnull.cont(function(){
return {};
})).and(be.restricted(global_data.selected_keys.arr)).err("key not recognized.").alt(V.strlist.empty.cont(function(list){
return {
'local': list
};
})).on(['initialize', 'silent'], be.bool.or(unu)).on('watch', V.watch.user).on('defarg', san_arr).on('verbose', str_to_num.or(unu)).on('ignore', V.ignore.user).on(['pre', 'remote', 'local', 'final'], V.execlist).on('rsync', V.rsync.init).on('defarg.required', V.defarg_required).on(['remotehost', 'remotefold'], be.str.or(unu.cont(function(v, key){
var origin;
origin = arguments[arguments.length - 1].origin;
return origin[key];
}))).cont(organize_rsync).and(V.rsync.throw_if_error).on('ssh', V.user_ssh).on('var', V.user_vars);
disp = function(num){
return function(){
return console.log(num);
};
};
V.def = be.obj.on(['remotehost', 'remotefold'], be.str.or(unu)).on(['silent'], be.bool.or(be.undefnull.cont(false))).on('verbose', str_to_num.or(be.undefnull.cont(0))).on('initialize', be.bool.or(be.undefnull.cont(true))).on('watch', V.watch.def).on('defarg', san_arr).on('defarg.required', V.defarg_required).on('ignore', V.ignore.def).on(['pre', 'local', 'final', 'remote'], V.execlist).on('rsync', V.rsync.init).on('var', V.def_vars).cont(organize_rsync).and(V.rsync.throw_if_error).on('ssh', V.def_ssh).map(function(value, key){
var state, def, user, put;
state = arguments[arguments.length - 1];
def = state.def, user = state.user;
switch (global_data.selected_keys.set.has(key)) {
case true:
def[key] = value;
break;
case false:
if (key.match("/")) {
return [false, [':incorrect-custom-name']];
}
put = V.user.auth(value, key, state);
if (put['continue']) {
user[key] = put.value;
} else {
return [false, [put.message], put.path];
}
}
return true;
}).cont(function(){
var ref$, user, def, cmdname, value, i$, len$, I;
ref$ = arguments[arguments.length - 1], user = ref$.user, def = ref$.def;
for (cmdname in user) {
value = user[cmdname];
handle_ssh(value, def);
for (i$ = 0, len$ = (ref$ = global_data.selected_keys.undef).length; i$ < len$; ++i$) {
I = ref$[i$];
if (value[I] === undefined) {
user[cmdname][I] = def[I];
} else {
user[cmdname][I] = value[I];
}
}
}
return {
user: user,
def: def
};
}).and(function(){
var info;
info = arguments[arguments.length - 1].info;
if (info.options.concat === 3) {
return [false, [':concat']];
}
return true;
}).er