From 330bd814ce60007ded1ed99a79ea968d4718d8bf Mon Sep 17 00:00:00 2001 From: gquadros Date: Fri, 26 Aug 2016 17:02:15 +0100 Subject: [PATCH] Allows options to be passed before actions. --- .../ibm/ws/lars/upload/cli/UploadFatTest.java | 27 +++++++++++++++++++ .../java/com/ibm/ws/lars/upload/cli/Main.java | 16 ++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/cli-client/src/fat/java/com/ibm/ws/lars/upload/cli/UploadFatTest.java b/cli-client/src/fat/java/com/ibm/ws/lars/upload/cli/UploadFatTest.java index 91a43a9..529f9e8 100644 --- a/cli-client/src/fat/java/com/ibm/ws/lars/upload/cli/UploadFatTest.java +++ b/cli-client/src/fat/java/com/ibm/ws/lars/upload/cli/UploadFatTest.java @@ -225,4 +225,31 @@ public void testNonEsa() throws Exception { assertEquals("Incorrect resource count", 0, connectionList.getAllResources().size()); assertEquals("Incorrect feature count", 0, connectionList.getAllFeatures().size()); } + + @Test + public void testOptionsBeforeAction() throws Exception { + RestRepositoryConnection repoConnection = (RestRepositoryConnection) repoServer.getAdminConnection(); + RepositoryConnectionList connectionList = new RepositoryConnectionList(repoConnection); + String esaPath = "resources/com.ibm.websphere.appserver.adminCenter-1.0.esa"; + File esaFile = new File(esaPath); + + TestProcess tp = new TestProcess(Arrays.asList(FatUtils.SCRIPT, + "--url=" + FatUtils.SERVER_URL, + "upload", + "--username=" + repoConnection.getUserId(), + "--password=" + repoConnection.getPassword(), + esaPath)); + tp.run(); + + tp.assertReturnCode(0); + assertEquals("Incorrect resource count", 1, connectionList.getAllResources().size()); + assertEquals("Incorrect feature count", 1, connectionList.getAllFeatures().size()); + + EsaResourceWritable resource = (EsaResourceWritable) connectionList.getAllFeatures().iterator().next(); + assertEquals("Incorrect state", State.PUBLISHED, resource.getState()); + assertEquals("Incorrect license type", LicenseType.UNSPECIFIED, resource.getLicenseType()); + assertEquals("Incorrect size", esaFile.length(), resource.getMainAttachmentSize()); + + tp.assertOutputContains("done"); + } } diff --git a/cli-client/src/main/java/com/ibm/ws/lars/upload/cli/Main.java b/cli-client/src/main/java/com/ibm/ws/lars/upload/cli/Main.java index 62f38c3..4e4b7b5 100644 --- a/cli-client/src/main/java/com/ibm/ws/lars/upload/cli/Main.java +++ b/cli-client/src/main/java/com/ibm/ws/lars/upload/cli/Main.java @@ -180,7 +180,18 @@ private List readActionAndOptions(String[] args) throws ClientException throw new ClientException("No options were given", 1, HelpDisplay.SHOW_HELP); } + // Allows options to be passed before actions. Considers the action that comes first. String actionString = args[0]; + int skipAction = 0; + for (int i = 0; i < args.length; i++) { + String tempActionString = args[i].startsWith("--") ? args[i].substring(2) : args[i]; + if (Action.getByArgument(tempActionString) != null) { + skipAction = i; + actionString = args[i]; + this.action = Action.getByArgument(args[i]); + break; + } + } // If we're not invoked from a script, the action should start with "--" if (getInvokedName() == null) { @@ -198,7 +209,10 @@ private List readActionAndOptions(String[] args) throws ClientException this.options = new HashMap(); boolean keepProcessingOptions = true; - for (int i = 1; i < args.length; i++) { + for (int i = 0; i < args.length; i++) { + if (skipAction == i) { + continue; + } String arg = args[i]; if (keepProcessingOptions && arg.equals("--")) {