support for command-line operations;
authorwenzelm
Sun, 11 Jul 2021 13:48:01 +0200
changeset 73962 5351719ab2a0
parent 73961 f090787bb4c4
child 73963 59b6f0462086
support for command-line operations;
src/Tools/Setup/isabelle/setup/Setup.java
--- a/src/Tools/Setup/isabelle/setup/Setup.java	Sun Jul 11 13:46:14 2021 +0200
+++ b/src/Tools/Setup/isabelle/setup/Setup.java	Sun Jul 11 13:48:01 2021 +0200
@@ -6,10 +6,65 @@
 
 package isabelle.setup;
 
+
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+
+
 class Setup
 {
+    private static void echo(String msg)
+    {
+        System.out.println(msg);
+
+    }
+    private static void fail(String msg)
+    {
+        echo(msg);
+        System.exit(2);
+    }
+
+    private static void check_args(boolean b)
+    {
+        if (!b) { fail("Bad command-line arguments"); }
+    }
+
     public static void main(String[] args)
     {
-        System.out.println("Isabelle setup");
+        int n = args.length;
+        check_args(n > 0);
+
+        String op = args[0];
+        try {
+            switch (op) {
+                case "build":
+                    check_args(n == 1);
+                    Build.build_components(false);
+                    break;
+                case "build_fresh":
+                    check_args(n == 1);
+                    Build.build_components(true);
+                    break;
+                case "classpath":
+                    check_args(n == 1);
+                    echo(Environment.join_standard_paths(Build.classpath()));
+                    break;
+                case "services":
+                    check_args(n == 1);
+                    for (String s : Build.services()) { echo(s); }
+                    break;
+                default:
+                    fail("Bad setup operation " + Environment.quote(op));
+                    break;
+            }
+        }
+        catch (InterruptedException e) {
+            echo("Interrupt");
+            System.exit(139);
+        }
+        catch (IOException | RuntimeException | NoSuchAlgorithmException e) {
+            echo(e.getMessage());
+            System.exit(1);
+        }
     }
 }