Commit d9c458d2 authored by redmitry@list.ru's avatar redmitry@list.ru

add parameters

parent 6142ea9a
......@@ -55,14 +55,15 @@ import org.eclipse.jgit.util.SystemReader;
public class Main {
private final static String HELP =
"java -jar biotools-populouse.jar -g -u -p [-b] [--path]\n\n" +
"java -jar biotools-populouse.jar -g -u -p [-b] [--path] [--dirs]\n\n" +
"parameters:\n\n" +
"-h (--help) - this help message\n" +
"-g (--git) - git endpoint\n" +
"-u (--user) 'username' - github username\n" +
"-p (--password) 'password' - github pasword\n" +
"-b (--branch) - git remote branch ['origin/master']\n" +
"--path - git path to put files ['/']\n\n" +
"--path - git path to put files ['/']\n" +
"--dirs - if present, put each tool into its own directory \n\n" +
"example: >java -jar biotools-populous.jar -g https://github.com/xyz.git --path /biotools -u redmitry -p xyz\n";
public final static String BRANCH = "origin/master";
......@@ -83,6 +84,8 @@ public class Main {
}
final List<String> path = params.get("--path");
final List<String> suffix = params.get("--suffix");
final String sfx = suffix == null || suffix.isEmpty() ? ".opeb.json" : suffix.get(0);
List<String> user = params.get("-u");
if (user == null) {
......@@ -108,12 +111,13 @@ public class Main {
final String b = branch == null || branch.isEmpty() ? null : branch.get(0);
process(g, b != null ? b : BRANCH,
path == null || path.isEmpty() ? "/" : path.get(0), u, p);
path == null || path.isEmpty() ? "/" : path.get(0),
params.get("--dirs") != null, sfx, u, p);
}
}
private static void process(final String endpoint, final String branch, final String path,
final String user, final String password) {
final boolean dirs, final String suffix, final String user, final String password) {
final int idx = branch.lastIndexOf('/');
final String local = idx < 0 ? branch : branch.substring(idx + 1);
......@@ -126,7 +130,7 @@ public class Main {
.build();
final FileSystem fs = Jimfs.newFileSystem(config);
final Path root = fs.getPath(path);
final Path root = fs.getPath("/");
try (Git git = Git.cloneRepository()
.setURI(endpoint)
......@@ -144,10 +148,18 @@ public class Main {
final Tool tool = BiotoolsConverter.convert(jtool);
final String _id = tool.getSummary().getToolID().trim();
final String _id = tool.getSummary().getToolID().trim().toLowerCase();
final String file_name = _id + ".json";
final Path file_path = root.resolve(file_name);
final Path dir = dirs ? root.resolve(path).resolve(_id) : root.resolve(path);
if (!Files.exists(dir)) {
try {
Files.createDirectories(dir);
} catch(IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "can't create dir: " + dir, ex.getMessage());
}
}
final Path file_path = dir.resolve(_id + suffix);
try (Writer writer = Files.newBufferedWriter(file_path)) {
jsonb.toJson(tool, writer);
......@@ -155,7 +167,7 @@ public class Main {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
git.add().addFilepattern(".").call();
git.commit().setMessage("biotools commit " + Instant.now()).call();
git.push().setRemote(branch).setCredentialsProvider(
......@@ -179,6 +191,8 @@ public class Main {
case "-b":
case "--branch":
case "--path":
case "--dirs":
case "--suffix":
case "-u":
case "--user":
case "-p":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment