Initial commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
usage:
|
||||
|
||||
`./fetch *repo*` to pull in a repo and setup symlinks.
|
||||
|
||||
`./fetch clean` to remove all repos, and symlinks.
|
||||
@@ -0,0 +1,101 @@
|
||||
import std.stdio;
|
||||
import std.file;
|
||||
import std.conv;
|
||||
import std.process;
|
||||
import std.array;
|
||||
import std.algorithm;
|
||||
|
||||
bool run_script(string script_command){
|
||||
try{
|
||||
writeln("calling::: " ~ script_command);
|
||||
auto cont = executeShell(script_command);
|
||||
if(cont.status != 0) {
|
||||
writeln("failed to run script command" ~cont.output);
|
||||
//return "Failed";
|
||||
return false;
|
||||
} else {
|
||||
writeln("script output " ~ cont.output);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
writeln("Failed to execute script");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main(string[] args) {
|
||||
writeln(args.length);
|
||||
if(args.length <= 1){
|
||||
writeln("You must provide a repo: fetch git.dreamphase.net/username/repo.git");
|
||||
return 1;
|
||||
}
|
||||
auto repo = args[1];
|
||||
if(repo == "clean"){
|
||||
try{
|
||||
if(getcwd() ~"/external/".exists){
|
||||
writeln("Removing all repos::\r\n");
|
||||
auto files = dirEntries(getcwd() ~"/external/", SpanMode.shallow).array();
|
||||
writeln(files);
|
||||
foreach (fpath; files) {
|
||||
auto delete_split = to!string(fpath).split("/");
|
||||
auto delete_path = getcwd() ~ "/" ~ delete_split[$-1];
|
||||
string clean_script = "rm " ~ delete_path;
|
||||
run_script(clean_script);
|
||||
clean_script = "rm " ~ delete_path ~ ".d";
|
||||
run_script(clean_script);
|
||||
}
|
||||
string clean_script = "rm -rf external/";
|
||||
run_script(clean_script);
|
||||
return 0;
|
||||
} else {
|
||||
writeln("Nothing to clean. `external` path doesn't exist.");
|
||||
return 1;
|
||||
}
|
||||
} catch (Exception e){
|
||||
writeln("Unable to clean");
|
||||
writeln(e.msg); // "error"
|
||||
writeln(e.file); // __FILE__
|
||||
writeln(e.line); // __LINE__ - 7
|
||||
}
|
||||
}
|
||||
try{
|
||||
writeln("Trying to fetcht: \r\n" ~ repo);
|
||||
string clone_script = "mkdir -p external >> /dev/null && cd external && git clone " ~ repo;
|
||||
auto result = run_script(clone_script);
|
||||
writeln("Clone output:: \r\n" ~result);
|
||||
writeln("repo has been cloned, setting up link.");
|
||||
|
||||
auto repo_split = repo.split("/");
|
||||
auto package_name = repo_split[repo_split.length-1].replace(".git","");
|
||||
writeln("Package name: " ~ package_name);
|
||||
|
||||
string package_base = getcwd() ~ "/external/" ~ package_name ~ "/source/";
|
||||
if(package_base.exists){
|
||||
auto files = dirEntries(package_base, SpanMode.shallow).array();
|
||||
writeln("PACKAGE path: \r\n");
|
||||
writeln(files);
|
||||
if(files.length >1){
|
||||
writeln("Unable to locate package internals.");
|
||||
|
||||
return 1;
|
||||
}
|
||||
auto package_path = to!string(files[0]);
|
||||
if(!package_path.canFind(".d")){
|
||||
package_path = package_path ~ "/package.d";
|
||||
string link_script = "ln -s " ~ package_path.replace(".d","") ~ " " ~ package_name;
|
||||
auto link_result = run_script(link_script);
|
||||
} else {
|
||||
string link_script = "ln -s " ~ package_path ~ " " ~ package_name ~ ".d";
|
||||
auto link_result = run_script(link_script);
|
||||
}
|
||||
} else {
|
||||
writeln("Unable to locate package internals.");
|
||||
return 1;
|
||||
}
|
||||
} catch (Exception e){
|
||||
writeln(e.msg); // "error"
|
||||
writeln(e.file); // __FILE__
|
||||
writeln(e.line); // __LINE__ - 7
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user