// Compiled by ClojureScript 0.0-2138
goog.provide('lt.objs.cli');
goog.require('cljs.core');
goog.require('lt.objs.app');
goog.require('lt.objs.files');
goog.require('lt.objs.opener');
goog.require('lt.objs.workspace');
goog.require('lt.objs.workspace');
goog.require('clojure.string');
goog.require('lt.objs.command');
goog.require('lt.objs.files');
goog.require('lt.objs.opener');
goog.require('lt.objs.app');
goog.require('clojure.string');
goog.require('lt.object');
goog.require('lt.object');
goog.require('lt.util.ipc');
goog.require('lt.util.ipc');
goog.require('lt.objs.command');
lt.objs.cli.remote = require("remote");
lt.objs.cli.open_paths = (function open_paths(path_line_pairs,add_QMARK_){var seq__7274 = cljs.core.seq.call(null,path_line_pairs);var chunk__7276 = null;var count__7277 = 0;var i__7278 = 0;while(true){
if((i__7278 < count__7277))
{var vec__7280 = cljs.core._nth.call(null,chunk__7276,i__7278);var path = cljs.core.nth.call(null,vec__7280,0,null);var line = cljs.core.nth.call(null,vec__7280,1,null);if(cljs.core.not_EQ_.call(null,path,process.execPath))
{if(cljs.core.truth_(lt.objs.files.exists_QMARK_.call(null,path)))
{if(cljs.core.truth_(lt.objs.files.dir_QMARK_.call(null,path)))
{lt.object.raise.call(null,lt.objs.workspace.current_ws,new cljs.core.Keyword(null,"add.folder!","add.folder!",2151595160),path);
} else
{lt.object.raise.call(null,lt.objs.opener.opener,new cljs.core.Keyword(null,"open!","open!",1119852169),path);
if(cljs.core.truth_(line))
{lt.objs.command.exec_BANG_.call(null,new cljs.core.Keyword(null,"goto-line","goto-line",2802035088),line);
} else
{}
if(cljs.core.truth_(add_QMARK_))
{lt.object.raise.call(null,lt.objs.workspace.current_ws,new cljs.core.Keyword(null,"add.file!","add.file!",4237252106),path);
} else
{}
}
} else
{lt.object.raise.call(null,lt.objs.opener.opener,new cljs.core.Keyword(null,"new!","new!",1017282035),path);
}
{
var G__7282 = seq__7274;
var G__7283 = chunk__7276;
var G__7284 = count__7277;
var G__7285 = (i__7278 + 1);
seq__7274 = G__7282;
chunk__7276 = G__7283;
count__7277 = G__7284;
i__7278 = G__7285;
continue;
}
} else
{{
var G__7286 = seq__7274;
var G__7287 = chunk__7276;
var G__7288 = count__7277;
var G__7289 = (i__7278 + 1);
seq__7274 = G__7286;
chunk__7276 = G__7287;
count__7277 = G__7288;
i__7278 = G__7289;
continue;
}
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__7274);if(temp__4092__auto__)
{var seq__7274__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__7274__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__7274__$1);{
var G__7290 = cljs.core.chunk_rest.call(null,seq__7274__$1);
var G__7291 = c__4262__auto__;
var G__7292 = cljs.core.count.call(null,c__4262__auto__);
var G__7293 = 0;
seq__7274 = G__7290;
chunk__7276 = G__7291;
count__7277 = G__7292;
i__7278 = G__7293;
continue;
}
} else
{var vec__7281 = cljs.core.first.call(null,seq__7274__$1);var path = cljs.core.nth.call(null,vec__7281,0,null);var line = cljs.core.nth.call(null,vec__7281,1,null);if(cljs.core.not_EQ_.call(null,path,process.execPath))
{if(cljs.core.truth_(lt.objs.files.exists_QMARK_.call(null,path)))
{if(cljs.core.truth_(lt.objs.files.dir_QMARK_.call(null,path)))
{lt.object.raise.call(null,lt.objs.workspace.current_ws,new cljs.core.Keyword(null,"add.folder!","add.folder!",2151595160),path);
} else
{lt.object.raise.call(null,lt.objs.opener.opener,new cljs.core.Keyword(null,"open!","open!",1119852169),path);
if(cljs.core.truth_(line))
{lt.objs.command.exec_BANG_.call(null,new cljs.core.Keyword(null,"goto-line","goto-line",2802035088),line);
} else
{}
if(cljs.core.truth_(add_QMARK_))
{lt.object.raise.call(null,lt.objs.workspace.current_ws,new cljs.core.Keyword(null,"add.file!","add.file!",4237252106),path);
} else
{}
}
} else
{lt.object.raise.call(null,lt.objs.opener.opener,new cljs.core.Keyword(null,"new!","new!",1017282035),path);
}
{
var G__7294 = cljs.core.next.call(null,seq__7274__$1);
var G__7295 = null;
var G__7296 = 0;
var G__7297 = 0;
seq__7274 = G__7294;
chunk__7276 = G__7295;
count__7277 = G__7296;
i__7278 = G__7297;
continue;
}
} else
{{
var G__7298 = cljs.core.next.call(null,seq__7274__$1);
var G__7299 = null;
var G__7300 = 0;
var G__7301 = 0;
seq__7274 = G__7298;
chunk__7276 = G__7299;
count__7277 = G__7300;
i__7278 = G__7301;
continue;
}
}
}
} else
{return null;
}
}
break;
}
});
/**
* Map of commandline options parsed by optimist
*/
lt.objs.cli.parsed_args = cljs.core.js__GT_clj.call(null,lt.objs.cli.remote.getGlobal("browserParsedArgs"),new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",4191781672),true);
/**
* Files to open from a file manager
*/
lt.objs.cli.open_files = cljs.core.js__GT_clj.call(null,lt.objs.cli.remote.getGlobal("browserOpenFiles"));
/**
* Arguments used to start LightTable
*/
lt.objs.cli.argv = cljs.core.js__GT_clj.call(null,lt.objs.cli.remote.process.argv);
lt.util.ipc.on.call(null,"openFileAfterStartup",(function (p1__7302_SHARP_){return lt.object.raise.call(null,lt.objs.app.app,new cljs.core.Keyword(null,"open!","open!",1119852169),p1__7302_SHARP_);
}));
/**
* Returns path arguments passed to executable or nil if none given. Only returns
* on first window since subsequent windows don't open path arguments.
*/
lt.objs.cli.args = (function args(){return (lt.objs.app.first_window_QMARK_.call(null)) && ((cljs.core.seq.call(null,lt.objs.cli.open_files)) || (cljs.core.seq.call(null,(cljs.core.truth_(process.env.LT_DEV_CLI)?cljs.core.subvec.call(null,lt.objs.cli.argv,2):cljs.core.rest.call(null,lt.objs.cli.argv)))));
});
lt.objs.cli.__BEH__open_on_args = (function __BEH__open_on_args(this$){if(lt.objs.app.first_window_QMARK_.call(null))
{var path_line_pairs = cljs.core.map.call(null,(function (p1__7303_SHARP_){var vec__7305 = cljs.core.re_find.call(null,/^(.*?):?(\d+)?$/,p1__7303_SHARP_);var _ = cljs.core.nth.call(null,vec__7305,0,null);var path = cljs.core.nth.call(null,vec__7305,1,null);var line = cljs.core.nth.call(null,vec__7305,2,null);return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [lt.objs.files.resolve.call(null,lt.objs.files.cwd,path),line], null);
}),lt.objs.cli.args.call(null));var paths = cljs.core.map.call(null,cljs.core.first,path_line_pairs);var open_dir_QMARK_ = cljs.core.some.call(null,lt.objs.files.dir_QMARK_,paths);if(cljs.core.truth_(open_dir_QMARK_))
{lt.object.merge_BANG_.call(null,lt.objs.workspace.current_ws,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"initialized?","initialized?",613820253),true], null));
lt.objs.command.exec_BANG_.call(null,new cljs.core.Keyword(null,"workspace.show","workspace.show",1768599592));
} else
{}
return lt.objs.cli.open_paths.call(null,path_line_pairs,new cljs.core.Keyword(null,"add","add",1014000659).cljs$core$IFn$_invoke$arity$1(lt.objs.cli.parsed_args));
} else
{return null;
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.cli","open-on-args","lt.objs.cli/open-on-args",3169685299),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.cli.__BEH__open_on_args,new cljs.core.Keyword(null,"desc","desc",1016984067),"App: Process commandline or file manager arguments",new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"post-init","post-init",2970371471),null], null), null));
lt.objs.cli.__BEH__open_BANG_ = (function __BEH__open_BANG_(this$,path){if(cljs.core._EQ_.call(null,lt.objs.app.fetch.call(null,new cljs.core.Keyword(null,"focusedWindow","focusedWindow",2946535865)),lt.objs.app.window_number.call(null)))
{return lt.objs.cli.open_paths.call(null,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [path], null)], null),new cljs.core.Keyword(null,"add","add",1014000659).cljs$core$IFn$_invoke$arity$1(lt.objs.cli.parsed_args));
} else
{return null;
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.cli","open!","lt.objs.cli/open!",969056930),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.cli.__BEH__open_BANG_,new cljs.core.Keyword(null,"desc","desc",1016984067),"App: Open path(s) from a file manager after startup",new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"open!","open!",1119852169),null], null), null));
