Factor error message generation into a separate file; add '-tc' flag to domtool-client
[hcoop/domtool2.git] / src / main.sml
index e106823..a8cf180 100644 (file)
@@ -176,7 +176,7 @@ fun context x =
           (print "Couldn't find your certificate.\nYou probably haven't been given any Domtool privileges.\n";
            raise e)
 
-fun requestContext f =
+fun setupUser () =
     let
        val user =
            case Posix.ProcEnv.getenv "DOMTOOL_USER" of
@@ -187,9 +187,15 @@ fun requestContext f =
                    Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
                end
              | SOME user => user
-                  
-       val () = Acl.read Config.aclFile
-       val () = Domain.setUser user
+    in
+       Acl.read Config.aclFile;
+       Domain.setUser user;
+       user
+    end
+
+fun requestContext f =
+    let
+       val user = setupUser ()
                 
        val () = f ()
 
@@ -242,6 +248,14 @@ fun request fname =
 
 fun requestDir dname =
     let
+       val _ = if Posix.FileSys.access (dname, []) then
+                   ()
+               else
+                   (print ("Can't access " ^ dname ^ ".\n");
+                    print "Did you mean to run domtool on a specific file, instead of asking for all\n";
+                    print "files in your ~/domtool directory?\n";
+                    OS.Process.exit OS.Process.failure)
+
        val _ = ErrorMsg.reset ()
 
        val (user, bio) = requestBio (fn () => checkDir dname)
@@ -796,10 +810,6 @@ fun regenerate context =
        val _ = ErrorMsg.reset ()
 
        val b = basis ()
-       val _ = if Env.lookupType b "string" then
-                   print "Still got it\n"
-               else
-                   print "Don't got it\n"
        val () = Tycheck.disallowExterns ()
 
        val () = Domain.resetGlobal ()
@@ -852,13 +862,15 @@ fun regenerate context =
                val (_, files) = Order.order (SOME b) files
            in
                if !ErrorMsg.anyErrors then
-                   print ("User " ^ user ^ "'s configuration has errors!\n")
+                   (ErrorMsg.reset ();
+                    print ("User " ^ user ^ "'s configuration has errors!\n"))
                else
                    app eval' files
            end
                handle IO.Io _ => ()
                     | OS.SysErr (s, _) => print ("System error processing user " ^ user ^ ": " ^ s ^ "\n")
-                    | ErrorMsg.Error => print ("User " ^ user ^ " had a compilation error.\n")
+                    | ErrorMsg.Error => (ErrorMsg.reset ();
+                                         print ("User " ^ user ^ " had a compilation error.\n"))
                     | _ => print "Unknown exception during regeneration!\n"
     in
        app contactNode Config.nodeIps;