X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fmain%2FCLI.java;h=0780e9fbdd6de3a79b8a031f5a5b1b71f2a1cc4c;hb=302eb7c9ef9b1b45e41f8dfdeda365be8fb6dfe8;hp=627517c97e11dae081ae8615f914e23111e12160;hpb=0cb56185ab6d47b5755e272dbe2cc55afc4764c3;p=jSite.git diff --git a/src/de/todesbaum/jsite/main/CLI.java b/src/de/todesbaum/jsite/main/CLI.java index 627517c..0780e9f 100644 --- a/src/de/todesbaum/jsite/main/CLI.java +++ b/src/de/todesbaum/jsite/main/CLI.java @@ -1,5 +1,5 @@ /* - * jSite - + * jSite - * Copyright (C) 2006 David Roden * * This program is free software; you can redistribute it and/or modify @@ -26,10 +26,11 @@ import de.todesbaum.jsite.application.InsertListener; import de.todesbaum.jsite.application.Node; import de.todesbaum.jsite.application.Project; import de.todesbaum.jsite.application.ProjectInserter; +import de.todesbaum.util.io.StreamCopier.ProgressListener; /** * Command-line interface for jSite. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class CLI implements InsertListener { @@ -60,7 +61,7 @@ public class CLI implements InsertListener { /** * Creates a new command-line interface. - * + * * @param args * The command-line arguments */ @@ -68,6 +69,7 @@ public class CLI implements InsertListener { if ((args.length == 0) || args[0].equals("-h") || args[0].equals("--help")) { outputWriter.println("\nParameters:\n"); + outputWriter.println(" --config-file="); outputWriter.println(" --node="); outputWriter.println(" --project="); outputWriter.println(" --local-directory="); @@ -79,11 +81,19 @@ public class CLI implements InsertListener { return; } - Configuration configuration = new Configuration(); - if (!configuration.createLockFile()) { - outputWriter.println("Lock file found!"); - return; + String configFile = System.getProperty("user.home") + "/.jSite/config7"; + for (String argument : args) { + String value = argument.substring(argument.indexOf('=') + 1).trim(); + if (argument.startsWith("--config-file=")) { + configFile = value; + } + } + + ConfigurationLocator configurationLocator = new ConfigurationLocator(); + if (configFile != null) { + configurationLocator.setCustomLocation(configFile); } + Configuration configuration = new Configuration(configurationLocator, configurationLocator.findPreferredLocation()); projectInserter.addInsertListener(this); projects = configuration.getProjects(); @@ -97,6 +107,10 @@ public class CLI implements InsertListener { Project currentProject = null; for (String argument : args) { + if (argument.startsWith("--config-file=")) { + /* we already parsed this one. */ + continue; + } String value = argument.substring(argument.indexOf('=') + 1).trim(); if (argument.startsWith("--node=")) { Node newNode = getNode(value); @@ -143,9 +157,11 @@ public class CLI implements InsertListener { } } + int errorCode = 1; if (currentProject != null) { if (insertProject(currentProject)) { outputWriter.println("Project \"" + currentProject.getName() + "\" successfully inserted."); + errorCode = 0; } else { outputWriter.println("Project \"" + currentProject.getName() + "\" was not successfully inserted."); } @@ -153,11 +169,13 @@ public class CLI implements InsertListener { configuration.setProjects(projects); configuration.save(); + + System.exit(errorCode); } /** * Returns the project with the given name. - * + * * @param name * The name of the project * @return The project, or null if no project could be found @@ -173,7 +191,7 @@ public class CLI implements InsertListener { /** * Returns the node with the given name. - * + * * @param name * The name of the node * @return The node, or null if no node could be found @@ -189,7 +207,7 @@ public class CLI implements InsertListener { /** * Inserts the given project. - * + * * @param currentProject * The project to insert * @return true if the insert finished successfully, @@ -201,7 +219,12 @@ public class CLI implements InsertListener { return false; } projectInserter.setProject(currentProject); - projectInserter.start(); + projectInserter.start(new ProgressListener() { + + public void onProgress(long copied, long length) { + System.out.print("Uploaded: " + copied + " / " + length + " bytes...\r"); + } + }); synchronized (lockObject) { while (!finished) { try { @@ -228,6 +251,13 @@ public class CLI implements InsertListener { /** * {@inheritDoc} */ + public void projectUploadFinished(Project project) { + outputWriter.println("Project \"" + project.getName() + "\" has been uploaded, starting insert..."); + } + + /** + * {@inheritDoc} + */ public void projectURIGenerated(Project project, String uri) { outputWriter.println("URI: " + uri); } @@ -257,7 +287,7 @@ public class CLI implements InsertListener { /** * Creates a new command-line interface with the given arguments. - * + * * @param args * The command-line arguments */