01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.cli.deployer;
17:
18: import org.apache.commons.cli.CommandLine;
19: import org.apache.commons.cli.CommandLineParser;
20: import org.apache.commons.cli.GnuParser;
21: import org.apache.commons.cli.Option;
22: import org.apache.commons.cli.OptionBuilder;
23: import org.apache.commons.cli.Options;
24: import org.apache.commons.cli.ParseException;
25: import org.apache.geronimo.cli.CLParserException;
26:
27: /**
28: * @version $Rev: 602983 $ $Date: 2007-12-10 10:20:09 -0800 (Mon, 10 Dec 2007) $
29: */
30: public class InstallLibraryCommandArgsImpl implements
31: InstallLibraryCommandArgs {
32: private final static String ARGUMENT_GROUP_ID_SHORTFORM = "g";
33: private final static String ARGUMENT_GROUP_ID = "groupId";
34:
35: protected final Options options;
36: protected CommandLine commandLine;
37:
38: public InstallLibraryCommandArgsImpl(String[] args)
39: throws CLParserException {
40: options = new Options();
41: addGroupId();
42:
43: CommandLineParser parser = new GnuParser();
44: try {
45: commandLine = parser.parse(options, args, true);
46: } catch (ParseException e) {
47: throw new CLParserException(e.getMessage(), e);
48: }
49:
50: if (0 == commandLine.getArgs().length) {
51: throw new CLParserException("Must specify a LibraryFile.");
52: } else if (1 < commandLine.getArgs().length) {
53: throw new CLParserException("Too many arguments.");
54: }
55: }
56:
57: protected void addGroupId() {
58: OptionBuilder optionBuilder = OptionBuilder.hasArg()
59: .withArgName(ARGUMENT_GROUP_ID);
60: optionBuilder = optionBuilder.withLongOpt(ARGUMENT_GROUP_ID);
61: optionBuilder = optionBuilder
62: .withDescription("If a groupId is provided, the library file will be installed under that groupId. "
63: + "Otherwise, default will be used.");
64: Option option = optionBuilder
65: .create(ARGUMENT_GROUP_ID_SHORTFORM);
66: options.addOption(option);
67: }
68:
69: public String getGroupId() {
70: return commandLine.getOptionValue(ARGUMENT_GROUP_ID_SHORTFORM);
71: }
72:
73: public String[] getArgs() {
74: return commandLine.getArgs();
75: }
76:
77: }
|