// 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__7840 = cljs.core.seq.call(null,path_line_pairs);var chunk__7842 = null;var count__7843 = 0;var i__7844 = 0;while(true){
if((i__7844 < count__7843))
{var vec__7846 = cljs.core._nth.call(null,chunk__7842,i__7844);var path = cljs.core.nth.call(null,vec__7846,0,null);var line = cljs.core.nth.call(null,vec__7846,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__7848 = seq__7840;
var G__7849 = chunk__7842;
var G__7850 = count__7843;
var G__7851 = (i__7844 + 1);
seq__7840 = G__7848;
chunk__7842 = G__7849;
count__7843 = G__7850;
i__7844 = G__7851;
continue;
}
} else
{{
var G__7852 = seq__7840;
var G__7853 = chunk__7842;
var G__7854 = count__7843;
var G__7855 = (i__7844 + 1);
seq__7840 = G__7852;
chunk__7842 = G__7853;
count__7843 = G__7854;
i__7844 = G__7855;
continue;
}
}
} else
{var temp__4092__auto__ = cljs.core.seq.call(null,seq__7840);if(temp__4092__auto__)
{var seq__7840__$1 = temp__4092__auto__;if(cljs.core.chunked_seq_QMARK_.call(null,seq__7840__$1))
{var c__4262__auto__ = cljs.core.chunk_first.call(null,seq__7840__$1);{
var G__7856 = cljs.core.chunk_rest.call(null,seq__7840__$1);
var G__7857 = c__4262__auto__;
var G__7858 = cljs.core.count.call(null,c__4262__auto__);
var G__7859 = 0;
seq__7840 = G__7856;
chunk__7842 = G__7857;
count__7843 = G__7858;
i__7844 = G__7859;
continue;
}
} else
{var vec__7847 = cljs.core.first.call(null,seq__7840__$1);var path = cljs.core.nth.call(null,vec__7847,0,null);var line = cljs.core.nth.call(null,vec__7847,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__7860 = cljs.core.next.call(null,seq__7840__$1);
var G__7861 = null;
var G__7862 = 0;
var G__7863 = 0;
seq__7840 = G__7860;
chunk__7842 = G__7861;
count__7843 = G__7862;
i__7844 = G__7863;
continue;
}
} else
{{
var G__7864 = cljs.core.next.call(null,seq__7840__$1);
var G__7865 = null;
var G__7866 = 0;
var G__7867 = 0;
seq__7840 = G__7864;
chunk__7842 = G__7865;
count__7843 = G__7866;
i__7844 = G__7867;
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__7868_SHARP_){return lt.object.raise.call(null,lt.objs.app.app,new cljs.core.Keyword(null,"open!","open!",1119852169),p1__7868_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__7869_SHARP_){var vec__7871 = cljs.core.re_find.call(null,/^(.*?):?(\d+)?$/,p1__7869_SHARP_);var _ = cljs.core.nth.call(null,vec__7871,0,null);var path = cljs.core.nth.call(null,vec__7871,1,null);var line = cljs.core.nth.call(null,vec__7871,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));
