package io.digdag.cli.client;

import io.digdag.cli.SystemExitException;
import io.digdag.client.DigdagClient;

import java.util.Map;

import static io.digdag.cli.SystemExitException.systemExit;

public class Version extends ClientCommand
{
    @Override
    public void mainWithClientException()
            throws Exception
    {
        DigdagClient client = buildClient(false);
        Map<String, Object> remoteVersion = client.getVersion();
        ln("Client version: " + version);
        ln("Server version: " + remoteVersion.getOrDefault("version", ""));
    }

    @Override
    public SystemExitException usage(String error)
    {
        err.println("Usage: " + programName + " version");
        err.println("  Options:");
        showCommonOptions();
        return systemExit(error);
    }
}

@@ -321,24 +321,84 @@
 ption%0A    %7B%0A
+        ln(%22Client version: %22 + version);%0A        try %7B%0A    
         Digd
@@ -443,16 +443,20 @@
         
+ 
+   
 Map%3CStri
@@ -512,46 +512,8 @@
     
-    ln(%22Client version: %22 + version);%0A
     
@@ -584,16 +584,155 @@
 , %22%22));%0A
+        %7D%0A        catch (Exception e) %7B%0A            ln(%22An error happened during getting Server version.%22);%0A            throw e;%0A        %7D%0A
     %7D%0A%0A 

Improve message in version command when it cannot get server version