001/* 002 * Copyright 2012-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.cli.command; 018 019import java.util.Collection; 020 021import org.springframework.boot.cli.command.options.OptionHandler; 022import org.springframework.boot.cli.command.options.OptionHelp; 023import org.springframework.boot.cli.command.status.ExitStatus; 024 025/** 026 * Base class for a {@link Command} that parse options using an {@link OptionHandler}. 027 * 028 * @author Phillip Webb 029 * @author Dave Syer 030 * @see OptionHandler 031 */ 032public abstract class OptionParsingCommand extends AbstractCommand { 033 034 private final OptionHandler handler; 035 036 protected OptionParsingCommand(String name, String description, 037 OptionHandler handler) { 038 super(name, description); 039 this.handler = handler; 040 } 041 042 @Override 043 public String getHelp() { 044 return this.handler.getHelp(); 045 } 046 047 @Override 048 public Collection<OptionHelp> getOptionsHelp() { 049 return this.handler.getOptionsHelp(); 050 } 051 052 @Override 053 public final ExitStatus run(String... args) throws Exception { 054 return this.handler.run(args); 055 } 056 057 protected OptionHandler getHandler() { 058 return this.handler; 059 } 060 061}