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.OptionGroup; 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: 476049 $ $Date: 2006-11-17 15:35:17 +1100 (Fri, 17 Nov 2006) $ 030 */ 031 public class ListModulesCommandArgs implements CommandArgs { 032 private final static String ARGUMENT_ALL_SHORTFORM = "a"; 033 private final static String ARGUMENT_ALL = "all"; 034 035 private final static String ARGUMENT_STARTED_SHORTFORM = "s"; 036 private final static String ARGUMENT_STARTED = "started"; 037 038 private final static String ARGUMENT_STOPPED_SHORTFORM = "t"; 039 private final static String ARGUMENT_STOPPED = "stopped"; 040 041 protected final Options options; 042 protected CommandLine commandLine; 043 044 public ListModulesCommandArgs(String[] args) throws CLParserException { 045 options = new Options(); 046 addState(); 047 048 CommandLineParser parser = new GnuParser(); 049 try { 050 commandLine = parser.parse(options, args, true); 051 } catch (ParseException e) { 052 throw new CLParserException(e.getMessage(), e); 053 } 054 } 055 056 public boolean isAll() { 057 return commandLine.hasOption(ARGUMENT_ALL_SHORTFORM); 058 } 059 060 public boolean isStarted() { 061 return commandLine.hasOption(ARGUMENT_STARTED_SHORTFORM); 062 } 063 064 public boolean isStopped() { 065 return commandLine.hasOption(ARGUMENT_STOPPED_SHORTFORM); 066 } 067 068 public String[] getArgs() { 069 return commandLine.getArgs(); 070 } 071 072 protected void addState() { 073 OptionGroup optionGroup = new OptionGroup(); 074 075 Option option = new Option(ARGUMENT_ALL_SHORTFORM, 076 ARGUMENT_ALL, 077 false, 078 "All modules will be listed."); 079 optionGroup.addOption(option); 080 081 option = new Option(ARGUMENT_STARTED_SHORTFORM, 082 ARGUMENT_STARTED, 083 false, 084 "Only started modules will be listed."); 085 optionGroup.addOption(option); 086 087 option = new Option(ARGUMENT_STOPPED_SHORTFORM, 088 ARGUMENT_STOPPED, 089 false, 090 "Only stopped modules will be listed."); 091 optionGroup.addOption(option); 092 093 options.addOptionGroup(optionGroup); 094 } 095 096 }