/**
 * Copyright 2017 Artem Labazin <xxlabaza@gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ru.xxlabaza.test.ping.cli;

import static ch.qos.logback.classic.Level.DEBUG;
import static ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME;

import ch.qos.logback.classic.Logger;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import java.io.File;
import lombok.val;
import org.slf4j.LoggerFactory;

/**
 * Command line arguments parser utility class.
 *
 * @author Artem Labazin <xxlabaza@gmail.com>
 * @since 24.06.2017
 */
public final class CommandLineParser {

    public static void parse (String[] args) {
        val commonOptions = new CommonOptions();

        val commander = JCommander.newBuilder()
                .programName("java -jar " + getProgramName())
                .addObject(commonOptions)
                .build();

        try {
            commander.parse(args);
        } catch (ParameterException ex) {
            System.err.format("\nParsing arguments failed.\n%s\n\n", ex.getMessage());
            commander.usage();
            System.exit(1);
        }

        if (commonOptions.isHelp()) {
            System.out.println("\nThe program’s aim is to test the IP network and to determine RTT (Round Trip Time)\n");
            commander.usage();
            System.exit(0);
        }

        if (commonOptions.isDebug()) {
            val root = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
            root.setLevel(DEBUG);
        }
    }

    private static String getProgramName () {
        val name = new File(CommandLineParser.class.getProtectionDomain()
                .getCodeSource()
                .getLocation()
                .getPath())
                .getName();

        return name.contains(".jar")
               ? name
               : "ping.jar";
    }

    private CommandLineParser () {
    }
}

@@ -1128,16 +1128,442 @@
 rser %7B%0A%0A
+    private static final String PROGRAM_NAME;%0A%0A    private static final String PROGRAM_DESCRIPTION;%0A%0A    private static final String ARGUMENTS_ERROR_PREFIX;%0A%0A    static %7B%0A        PROGRAM_NAME = %22java -jar %22 + getProgramName();%0A        PROGRAM_DESCRIPTION = %22%5CnThe program%E2%80%99s aim is to test the IP network and to determine RTT (Round Trip Time)%5Cn%22;%0A        ARGUMENTS_ERROR_PREFIX = %22%5CnParsing arguments failed.%5Cn%25s%5Cn%5Cn%22;%0A    %7D%0A%0A
     publ
@@ -1597,24 +1597,24 @@
 g%5B%5D args) %7B%0A
-
         val 
@@ -1732,39 +1732,20 @@
 ame(
-%22java -jar %22 + getProgramName()
+PROGRAM_NAME
 )%0A  
@@ -1936,45 +1936,30 @@
 mat(
-%22%5CnParsing arguments failed.%5Cn%25s%5Cn%5Cn%22
+ARGUMENTS_ERROR_PREFIX
 , ex
@@ -2117,96 +2117,27 @@
 tln(
-%22%5CnThe program%E2%80%99s aim is to test the IP network and to determine RTT (Round Trip Time)%5Cn%22
+PROGRAM_DESCRIPTION
 );%0A 

Move strings to static variables.