package com.crowdin.cli;

import com.crowdin.cli.commands.RootCommand;
import com.crowdin.cli.commands.parts.HelpCommand;
import com.crowdin.cli.utils.MessageSource;
import com.crowdin.cli.utils.Utils;
import picocli.CommandLine;

public class Cli {

    public static void main(String[] args) {
        try {
            CommandLine.Help.ColorScheme colorScheme = buildColorScheme();
            CommandLine.IExecutionExceptionHandler executionExceptionHandler = buildExecutionExceptionHandler();
            CommandLine commandLine = new CommandLine(new RootCommand())
                .setExecutionExceptionHandler(executionExceptionHandler)
                .setColorScheme(colorScheme);

            HelpCommand.setOptions(System.out, colorScheme);
            int exitCode = commandLine.execute(args);

            Utils.getNewVersionMassage().ifPresent(System.out::println);

            System.exit(exitCode);
        } catch (Exception e) {
            System.out.println("There is exception:");
            e.printStackTrace();
        }
    }

    private static CommandLine.Help.ColorScheme buildColorScheme() {
        return new CommandLine.Help.ColorScheme.Builder()
                .commands(CommandLine.Help.Ansi.Style.fg_yellow)
                .options(CommandLine.Help.Ansi.Style.fg_yellow)
                .build();
    }

    private static CommandLine.IExecutionExceptionHandler buildExecutionExceptionHandler() {
        return (ex, cmd, pr) -> {
            if (pr.originalArgs().contains("--debug")) {
                ex.printStackTrace();
            } else {
                cmd.getErr().println(ex.getMessage());
                Throwable cause = ex;
                while ((cause = cause.getCause()) != null) {
                    cmd.getErr().println(cause.getMessage());
                }
            }
            return cmd.getExitCodeExceptionMapper() != null
                    ? cmd.getExitCodeExceptionMapper().getExitCode(ex)
                    : cmd.getCommandSpec().exitCodeOnExecutionException();
        };
    }
}

@@ -119,52 +119,8 @@
 nd;%0A
-import com.crowdin.cli.utils.MessageSource;%0A
 impo
@@ -151,16 +151,16 @@
 .Utils;%0A
+
 import p
@@ -259,16 +259,51 @@
   try %7B%0A
+            setSystemProperties();%0A
         
@@ -987,16 +987,16 @@
 ion:%22);%0A
-
         
@@ -1029,32 +1029,693 @@
        %7D%0A    %7D%0A%0A
+    private static void setSystemProperties() %7B%0A        if (System.getenv(%22HTTP_PROXY_HOST%22) != null) %7B%0A            System.setProperty(%22http.proxyHost%22, System.getenv(%22HTTP_PROXY_HOST%22));%0A        %7D%0A        if (System.getenv(%22HTTP_PROXY_PORT%22) != null) %7B%0A            System.setProperty(%22http.proxyPort%22, System.getenv(%22HTTP_PROXY_PORT%22));%0A        %7D%0A        if (System.getenv(%22HTTPS_PROXY_HOST%22) != null) %7B%0A            System.setProperty(%22https.proxyHost%22, System.getenv(%22HTTPS_PROXY_HOST%22));%0A        %7D%0A        if (System.getenv(%22HTTPS_PROXY_PORT%22) != null) %7B%0A            System.setProperty(%22https.proxyPort%22, System.getenv(%22HTTPS_PROXY_PORT%22));%0A        %7D%0A    %7D%0A%0A
     private stat

Set proxy properties from system environment