001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.cli.deployer;
018
019 import org.apache.commons.cli.CommandLine;
020 import org.apache.commons.cli.CommandLineParser;
021 import org.apache.commons.cli.GnuParser;
022 import org.apache.commons.cli.Option;
023 import org.apache.commons.cli.OptionBuilder;
024 import org.apache.commons.cli.Options;
025 import org.apache.commons.cli.ParseException;
026 import org.apache.geronimo.cli.CLParserException;
027
028 /**
029 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
030 */
031 public class InstallLibraryCommandArgsImpl implements InstallLibraryCommandArgs {
032 private final static String ARGUMENT_GROUP_ID_SHORTFORM = "g";
033 private final static String ARGUMENT_GROUP_ID = "groupId";
034
035 protected final Options options;
036 protected CommandLine commandLine;
037
038 public InstallLibraryCommandArgsImpl(String[] args) throws CLParserException {
039 options = new Options();
040 addGroupId();
041
042 CommandLineParser parser = new GnuParser();
043 try {
044 commandLine = parser.parse(options, args, true);
045 } catch (ParseException e) {
046 throw new CLParserException(e.getMessage(), e);
047 }
048
049 if (0 == commandLine.getArgs().length) {
050 throw new CLParserException("Must specify a LibraryFile.");
051 } else if (1 < commandLine.getArgs().length) {
052 throw new CLParserException("Too many arguments.");
053 }
054 }
055
056 protected void addGroupId() {
057 OptionBuilder optionBuilder = OptionBuilder.hasArg().withArgName(ARGUMENT_GROUP_ID);
058 optionBuilder = optionBuilder.withLongOpt(ARGUMENT_GROUP_ID);
059 optionBuilder = optionBuilder
060 .withDescription("If a groupId is provided, the library file will be installed under that groupId. "+
061 "Otherwise, default will be used.");
062 Option option = optionBuilder.create(ARGUMENT_GROUP_ID_SHORTFORM);
063 options.addOption(option);
064 }
065
066 public String getGroupId() {
067 return commandLine.getOptionValue(ARGUMENT_GROUP_ID_SHORTFORM);
068 }
069
070 public String[] getArgs() {
071 return commandLine.getArgs();
072 }
073
074 }