@@ -0,0 +1,2608 @@
+/*%0D%0A * Copyright 2011 the original author or authors.%0D%0A *%0D%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A * you may not use this file except in compliance with the License.%0D%0A * You may obtain a copy of the License at%0D%0A *%0D%0A * http://www.apache.org/licenses/LICENSE-2.0%0D%0A *%0D%0A * Unless required by applicable law or agreed to in writing, software%0D%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A * See the License for the specific language governing permissions and%0D%0A * limitations under the License.%0D%0A */%0D%0A%0D%0Apackage com.trigonic.utils.spring.cmdline;%0D%0A%0D%0Aimport static java.lang.System.out;%0D%0A%0D%0Aimport java.io.File;%0D%0A%0D%0A/**%0D%0A * The command-line application under Spring Command Line is a bean initialized in the usual Spring way.%0D%0A * Values are pulled from the command-line under guidance of annotations on bean properties.%0D%0A */%0D%0Apublic class SampleApplication implements Runnable %7B%0D%0A    private boolean verbose;%0D%0A    private File file;%0D%0A    private String%5B%5D messages;%0D%0A%0D%0A    /**%0D%0A     * Flag options are set to true if they are specified on the command line.%0D%0A     */%0D%0A    @Option(shortName = %22v%22, longName = %22verbose%22, description = %22verbose messages%22)%0D%0A    public void setVerbose(boolean verbose) %7B%0D%0A        this.verbose = verbose;%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * Options with values are converted by Spring in the normal way into the necessary property type.%0D%0A     */%0D%0A    @Option(shortName = %22f%22, longName = %22file%22, description = %22file%22)%0D%0A    public void setFile(File file) %7B%0D%0A        this.file = file;%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * Operands are specified similarly.%0D%0A     */%0D%0A    @Operand(index = 0, description = %22messages%22)%0D%0A    public void setMessage(String%5B%5D messages) %7B%0D%0A        this.messages = messages;%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * Simple way to run the application is the CommandLineAppContext's run method, which manages%0D%0A     * the lifecycle of the application and invokes the bean's Runnable.run method.  This example%0D%0A     * loads the applicationContext.xml file from the classpath into a parent application context%0D%0A     * used by the one that loads the application.%0D%0A     */%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A        new CommandLineAppContext().run(SampleApplication.class, args);%0D%0A    %7D%0D%0A%0D%0A    public void run() %7B%0D%0A        if (verbose) %7B%0D%0A            out.println(%22Verbose!%22);%0D%0A        %7D%0D%0A        if (file != null) %7B%0D%0A            out.println(%22File: %22 + file);%0D%0A        %7D%0D%0A        for (String message : messages) %7B%0D%0A            out.println(message);%0D%0A        %7D%0D%0A    %7D%0D%0A%7D%0D%0A

add sample demonstration app