changeset 1865:ecc44dd16172

Update Repoint
author Chris Cannam
date Tue, 19 Jun 2018 14:58:06 +0100
parents 3c47a2a5e85d
children 65d244ee39f9
files repoint.sml
diffstat 1 files changed, 47 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/repoint.sml	Mon Jun 18 14:17:26 2018 +0100
+++ b/repoint.sml	Tue Jun 19 14:58:06 2018 +0100
@@ -38,7 +38,7 @@
     authorization.
 *)
 
-val repoint_version = "1.0"
+val repoint_version = "1.1"
 
 
 datatype vcs =
@@ -136,6 +136,7 @@
 structure RepointFilenames = struct
     val project_file = "repoint-project.json"
     val project_lock_file = "repoint-lock.json"
+    val project_completion_file = ".repoint.point"
     val user_config_file = ".repoint.json"
     val archive_dir = ".repoint-archive"
 end
@@ -215,6 +216,7 @@
     val nonempty_dir_exists : string -> bool
     val project_spec_path : string -> string
     val project_lock_path : string -> string
+    val project_completion_path : string -> string
     val verbose : unit -> bool
 end = struct
 
@@ -272,6 +274,9 @@
     fun project_lock_path rootpath =
         project_file_path rootpath (RepointFilenames.project_lock_file)
 
+    fun project_completion_path rootpath =
+        project_file_path rootpath (RepointFilenames.project_completion_file)
+
     fun trim str =
         hd (String.fields (fn x => x = #"\n" orelse x = #"\r") str)
             
@@ -2420,7 +2425,14 @@
     in
         JsonBits.save_json_to lock_file lock_json
     end
-        
+
+fun checkpoint_completion_file rootpath =
+    let val completion_file = FileBits.project_completion_path rootpath
+        val stream = TextIO.openOut completion_file
+    in
+        TextIO.closeOut stream
+    end
+                                                               
 fun pad_to n str =
     if n <= String.size str then str
     else pad_to n (str ^ " ")
@@ -2586,8 +2598,12 @@
         val _ = if List.exists (fn (_, OK _) => true | _ => false) outcomes
                 then lock_project project
                 else OS.Process.success
+        val return_code = return_code_for outcomes
     in
-        return_code_for outcomes
+        if OS.Process.isSuccess return_code
+        then checkpoint_completion_file (#rootpath context)
+        else ();
+        return_code
     end
     
 fun load_local_project pintype =
@@ -2628,7 +2644,7 @@
      print ("\n  A simple manager for third-party source code dependencies.\n"
             ^ "  http://all-day-breakfast.com/repoint/\n\n"
             ^ "Usage:\n\n"
-            ^ "  repoint <command>\n\n"
+            ^ "  repoint <command> [<options>]\n\n"
             ^ "where <command> is one of:\n\n"
             ^ "  status   print quick report on local status only, without using network\n"
             ^ "  review   check configured libraries against their providers, and report\n"
@@ -2637,7 +2653,11 @@
             ^ "  lock     rewrite lock file to match local library status\n"
             ^ "  archive  pack up project and all libraries into an archive file:\n"
             ^ "           invoke as 'repoint archive targetfile.tar.gz --exclude unwanted.txt'\n"
-            ^ "  version  print the Repoint version number and exit\n\n");
+            ^ "  version  print the Repoint version number and exit\n\n"
+            ^ "and <options> may include:\n\n"
+            ^ "  --directory <dir>\n"
+            ^ "           change to directory <dir> before doing anything; in particular,\n"
+            ^ "           expect to find project spec file in that directory\n\n");
     OS.Process.failure)
 
 fun archive target args =
@@ -2648,8 +2668,26 @@
         with_local_project USE_LOCKFILE (Archive.archive (target, xs))
       | _ => usage ()
 
+fun handleSystemArgs args =
+    let fun handleSystemArgs' leftover args =
+            case args of
+                "--directory"::dir::rest =>
+                (OS.FileSys.chDir dir;
+                 handleSystemArgs' leftover rest)
+              | arg::rest =>
+                handleSystemArgs' (leftover @ [arg]) rest
+              | [] => leftover
+    in
+        OK (handleSystemArgs' [] args)
+        handle e => ERROR (exnMessage e)
+    end
+                   
 fun repoint args =
-    let val return_code = 
+    case handleSystemArgs args of
+        ERROR e => (print ("Error: " ^ e ^ "\n");
+                    OS.Process.exit OS.Process.failure)
+      | OK args => 
+        let val return_code = 
             case args of
                 ["review"] => review ()
               | ["status"] => status ()
@@ -2661,10 +2699,9 @@
               | arg::_ => (print ("Error: unknown argument \"" ^ arg ^ "\"\n");
                            usage ())
               | _ => usage ()
-    in
-        OS.Process.exit return_code;
-        ()
-    end
+        in
+            OS.Process.exit return_code
+        end
         
 fun main () =
     repoint (CommandLine.arguments ())