Fix calculation of project size.
[jSite.git] / src / de / todesbaum / jsite / main / CLI.java
index 668720b..65c9253 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * jSite -
- * Copyright (C) 2006 David Roden
+ * jSite - CLI.java - Copyright © 2006–2012 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -89,11 +88,11 @@ public class CLI implements InsertListener {
                        }
                }
 
-               Configuration configuration = new Configuration(configFile);
-               if (!configuration.createLockFile()) {
-                       outputWriter.println("Lock file found!");
-                       return;
+               ConfigurationLocator configurationLocator = new ConfigurationLocator();
+               if (configFile != null) {
+                       configurationLocator.setCustomLocation(configFile);
                }
+               Configuration configuration = new Configuration(configurationLocator, configurationLocator.findPreferredLocation());
 
                projectInserter.addInsertListener(this);
                projects = configuration.getProjects();
@@ -107,6 +106,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);
@@ -153,9 +156,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.");
                        }
@@ -163,6 +168,8 @@ public class CLI implements InsertListener {
 
                configuration.setProjects(projects);
                configuration.save();
+
+               System.exit(errorCode);
        }
 
        /**
@@ -244,7 +251,7 @@ public class CLI implements InsertListener {
         * {@inheritDoc}
         */
        public void projectUploadFinished(Project project) {
-               outputWriter.println("Project \"" + project.getName() + "\" has ben uploaded, starting insert...");
+               outputWriter.println("Project \"" + project.getName() + "\" has been uploaded, starting insert...");
        }
 
        /**