package com.lexicalscope.jewel.cli;

/**
 * Constructs a Cli from an annotated interface definition.
 * 
 * @see com.lexicalscope.jewel.cli.Option
 * 
 * @author Tim Wood
 */
public abstract class CliFactory
{
    /**
     * Construct a Cli from an annotated interface definition
     * 
     * @param <O>
     *            The type of the interface that will be used to present the
     *            arguments
     * @param klass
     *            The annotated interface definition
     * 
     * @return A Cli configured to create instance of klass
     */
    public static <O> Cli<O> createCli(final Class<O> klass)
    {
        return new CliInterfaceImpl<O>(klass);
    }

    /**
     * Construct a Cli from an annotated class
     * 
     * @param <O>
     *            The type of the class used to present the arguments
     * @param options
     *            The annotated class
     * 
     * @return A Cli configured to configure the options
     */
    public static <O> Cli<O> createCliUsingInstance(final O options)
    {
        return new CliInstanceImpl<O>(options);
    }

    /**
     * Parse arguments from an annotated interface definition
     * 
     * @param <O>
     *            The type of the interface that will be used to present the
     *            arguments
     * @param klass
     *            The annotated interface definition
     * @param arguments
     * 
     * @return The parsed arguments
     * 
     * @throws CliValidationException
     */
    public static <O> O parseArguments(final Class<O> klass, final String... arguments)
            throws CliValidationException
    {
        return createCli(klass).parseArguments(arguments);
    }

    /**
     * Parse arguments from an annotated class instance
     * 
     * @param <O>
     *            The type of the class used to present the arguments
     * @param klass
     *            The annotated interface definition
     * @param arguments
     * 
     * @return The parsed arguments
     * 
     * @throws CliValidationException
     */
    public static <O> O parseArgumentsUsingInstance(final O options, final String... arguments)
            throws CliValidationException
    {
        return createCliUsingInstance(options).parseArguments(arguments);
    }
}

@@ -562,24 +562,207 @@
 e of klass%0D%0A
+     * %0D%0A     * @throws CliValidationException the arguments do not meet the CLI specification%0D%0A     * @throws InvalidOptionSpecificationException the CLI specification is not valid%0D%0A
      */%0D%0A   
@@ -818,16 +818,59 @@
 %3E klass)
+ throws InvalidOptionSpecificationException
 %0D%0A    %7B%0D
@@ -1208,24 +1208,207 @@
 he options%0D%0A
+     * %0D%0A     * @throws CliValidationException the arguments do not meet the CLI specification%0D%0A     * @throws InvalidOptionSpecificationException the CLI specification is not valid%0D%0A
      */%0D%0A   
@@ -1472,16 +1472,59 @@
 options)
+ throws InvalidOptionSpecificationException
 %0D%0A    %7B%0D
@@ -1973,32 +1973,167 @@
 idationException
+ the arguments do not meet the CLI specification%0D%0A     * @throws InvalidOptionSpecificationException the CLI specification is not valid
 %0D%0A     */%0D%0A    p
@@ -2249,34 +2249,79 @@
 idationException
-%0D%0A
+, InvalidOptionSpecificationException%0D%0A        
     %7B%0D%0A        r
@@ -2367,24 +2367,32 @@
 rguments);%0D%0A
+        
     %7D%0D%0A%0D%0A   
@@ -2741,24 +2741,159 @@
 ionException
+ the arguments do not meet the CLI specification%0D%0A     * @throws InvalidOptionSpecificationException the CLI specification is not valid
 %0D%0A     */%0D%0A 
@@ -3021,34 +3021,79 @@
 idationException
-%0D%0A
+, InvalidOptionSpecificationException%0D%0A        
     %7B%0D%0A        r
@@ -3154,22 +3154,30 @@
 rguments);%0D%0A
+        
     %7D%0D%0A%7D%0D%0A

add javadoc for new exceptions