Coverage Report - com.lexicalscope.jewel.cli.AbstractCliImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractCliImpl
81%
9/11
N/A
1
 
 1  
 package com.lexicalscope.jewel.cli;
 2  
 
 3  
 import static com.lexicalscope.jewel.cli.parser.DefaultArgumentParserFactory.createDefaultArgumentParser;
 4  
 import static com.lexicalscope.jewel.cli.validation.DefaultValidatorFactory.createDefaultValidator;
 5  
 
 6  
 import com.lexicalscope.fluentreflection.FluentClass;
 7  
 import com.lexicalscope.jewel.cli.specification.CliSpecification;
 8  
 import com.lexicalscope.jewel.cli.specification.OptionsSpecification;
 9  
 
 10  
 /*
 11  
  * Copyright 2011 Tim Wood
 12  
  *
 13  
  * Licensed under the Apache License, Version 2.0 (the "License");
 14  
  * you may not use this file except in compliance with the License.
 15  
  * You may obtain a copy of the License at
 16  
  *
 17  
  * http://www.apache.org/licenses/LICENSE-2.0
 18  
  *
 19  
  * Unless required by applicable law or agreed to in writing, software
 20  
  * distributed under the License is distributed on an "AS IS" BASIS,
 21  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 22  
  * See the License for the specific language governing permissions and
 23  
  * limitations under the License.
 24  
  */
 25  
 
 26  
 abstract class AbstractCliImpl<O> implements Cli<O> {
 27  
     private final FluentClass<O> klass;
 28  
     private final OptionsSpecification<O> optionsSpecification;
 29  
 
 30  
     public AbstractCliImpl(
 31  
             final FluentClass<O> klass,
 32  226
             final OptionsSpecification<O> optionsSpecification) {
 33  226
         this.klass = klass;
 34  226
         this.optionsSpecification = optionsSpecification;
 35  226
     }
 36  
 
 37  
     @Override public O parseArguments(final String... arguments) throws ArgumentValidationException {
 38  208
         final ArgumentCollectionBuilder parsedArguments = new ArgumentCollectionBuilder();
 39  
 
 40  208
         createDefaultArgumentParser().parseArguments(parsedArguments, arguments);
 41  
 
 42  204
         return argumentPresenter(klass, optionsSpecification).presentArguments(parsedArguments.processArguments(createDefaultValidator(optionsSpecification)));
 43  
     }
 44  
 
 45  
     protected abstract ArgumentPresenterImpl<O> argumentPresenter(
 46  
             FluentClass<O> klass,
 47  
             OptionsSpecification<O> specification);
 48  
 
 49  
     @Override public String getHelpMessage() {
 50  18
         return optionsSpecification.toString();
 51  
     }
 52  
 
 53  
     CliSpecification getSpecification() {
 54  2
         return optionsSpecification;
 55  
     }
 56  
 
 57  
     @Override public void describeTo(final HelpMessage helpMessage) {
 58  0
         optionsSpecification.describeTo(helpMessage);
 59  0
     }
 60  
 }