/*
 * App.java
 *
 * Copyright (C) 2017 [ A Legge Up ] <stephen@aleggeup.com>
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

package com.aleggeup.confagrid;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import com.aleggeup.confagrid.words.Phrase;

/**
 * App entry point.
 *
 * @author Stephen Legge <stephen@aleggeup.com>
 */
public class App {

    private final static Option help = Option.builder("h").longOpt("help").desc("print this message").build();

    private final static Option input = Option.builder("i")
            .longOpt("input").desc("phrase input file")
            .hasArg().argName("FILE")
            .build();

    public static void main(final String[] args) {
        final Options options = new Options();
        options.addOption(help);
        options.addOption(input);

        final CommandLineParser parser = new DefaultParser();

        try {
            final CommandLine cmdLine = parser.parse(options, args);
            if (cmdLine.hasOption("help")) {
                final HelpFormatter helpFormatter = new HelpFormatter();
                helpFormatter.printHelp("confagrid", options, true);
            } else if (cmdLine.hasOption("input")) {
                final String filename = cmdLine.getOptionValue("input");

                try (final Stream<String> stream = Files.lines(Paths.get(filename))) {
                    stream.forEach(App::writePhrase);
                } catch (final IOException e) {
                    e.printStackTrace();
                }
            }

        } catch (final ParseException e) {
            System.err.println("Parsing failed.  Reason: " + e.getMessage());
        }
    }

    public static void writePhrase(final String line) {
        final Phrase phrase = new Phrase(line);
        System.out.println(phrase.toString());
    }
}

@@ -818,69 +818,400 @@
 ate 
-final static Option help = Option.builder(%22h%22).longOpt(%22help%22
+static final String APP_NAME = %22confagrid%22;%0A%0A    private static final String OPTION_LONG_INPUT = %22input%22;%0A    private static final String OPTION_LONG_HELP = %22help%22;%0A%0A    private static final String OPTION_SHORT_INPUT = %22i%22;%0A    private static final String OPTION_SHORT_HELP = %22h%22;%0A%0A    private static final Option help = Option.builder(OPTION_SHORT_HELP)%0A            .longOpt(OPTION_LONG_HELP
 ).de
@@ -1261,21 +1261,21 @@
 ate 
-final 
 static 
+final 
 Opti
@@ -1300,19 +1300,34 @@
 builder(
-%22i%22
+OPTION_SHORT_INPUT
 )%0A      
@@ -1341,23 +1341,33 @@
 longOpt(
-%22input%22
+OPTION_LONG_INPUT
 ).desc(%22
@@ -1793,22 +1793,32 @@
 sOption(
-%22help%22
+OPTION_LONG_HELP
 )) %7B%0A   
@@ -1927,27 +1927,24 @@
 intHelp(
-%22confagrid%22
+APP_NAME
 , option
@@ -1994,23 +1994,33 @@
 sOption(
-%22input%22
+OPTION_LONG_INPUT
 )) %7B%0A   
@@ -2079,23 +2079,33 @@
 onValue(
-%22input%22
+OPTION_LONG_INPUT
 );%0A%0A    

Clean up some of the repeated strings with options