package io.digdag.cli.client;

import io.digdag.cli.SystemExitException;
import io.digdag.client.DigdagClient;
import io.digdag.client.api.RestProject;
import io.digdag.client.api.RestProjectCollection;

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

public class ShowProjects
        extends ClientCommand
{
    @Override
    public void mainWithClientException()
            throws Exception
    {
        DigdagClient client = buildClient();

        RestProjectCollection projects = client.getProjects();
        for (RestProject proj : projects.getProjects()) {
            ln(proj.getName());
            ln("  id: " + proj.getId());
            ln("  revision: " + proj.getRevision());
            ln("  archive type: " + proj.getArchiveType());
            ln("  project created at: " + proj.getCreatedAt());
            ln("  revision updated at: " + proj.getUpdatedAt());
            ln("");
        }
        err.println("Use `" + programName + " workflows <project-name>` to show details.");
    }

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

@@ -66,16 +66,47 @@
 eption;%0A
+import io.digdag.cli.TimeUtil;%0A
 import i
@@ -135,16 +135,16 @@
 Client;%0A
-
 import i
@@ -543,24 +543,48 @@
 Projects();%0A
+        ln(%22Projects%22);%0A
         for 
@@ -644,16 +644,30 @@
      ln(
+%22  name: %25s%22, 
 proj.get
@@ -697,19 +697,20 @@
 (%22  id: 
-%22 +
+%25s%22,
  proj.ge
@@ -745,19 +745,20 @@
 vision: 
-%22 +
+%25s%22,
  proj.ge
@@ -803,19 +803,20 @@
 e type: 
-%22 +
+%25s%22,
  proj.ge
@@ -862,36 +862,57 @@
 ect created at: 
-%22 + 
+%25s%22, TimeUtil.formatTime(
 proj.getCreatedA
@@ -907,32 +907,33 @@
 .getCreatedAt())
+)
 ;%0A            ln
@@ -957,20 +957,41 @@
 ted at: 
-%22 + 
+%25s%22, TimeUtil.formatTime(
 proj.get
@@ -1002,16 +1002,17 @@
 tedAt())
+)
 ;%0A      

Change output format like digdag sessions