Yaron Minsky avatar Yaron Minsky committed f746c76

fixed indentation en masse

Comments (0)

Files changed (8)

   lazy (
     let stop_ivar = Ivar.create () in
     Signal.handle [Signal.term] ~f:(fun (_:Signal.t) ->
-        Ivar.fill stop_ivar ());
+      Ivar.fill stop_ivar ());
     Ivar.read stop_ivar
   )
 
   Command.Spec.(
     empty
     +> flag "-username" (optional username_spec)
-      ~doc:"Username to act as"
+         ~doc:"Username to act as"
   )
 
 let days_flag () =
 
 let shell_run cmd args =
   In_thread.run(fun () ->
-      Core_extended.Shell.run_full cmd args)
+    Core_extended.Shell.run_full cmd args)
 
 let clear_string =
   lazy (shell_run "clear" [])
   let states = [| "|" ; "/"; "-"; "\\" |] in
   let pos = ref 0 in
   every (sec 1.0) (fun () -> 
-      pos := (!pos + 1) % Array.length states);
+    pos := (!pos + 1) % Array.length states);
   fun () -> states.(!pos)
 )
 
     (fun _ r w ->
        Rpc.Connection.create r w ~connection_state:()
        >>= function
-         | Error exn -> raise exn
-         | Ok conn -> f conn
+       | Error exn -> raise exn
+       | Ok conn -> f conn
     )
 
 let resolve_username username config =
     -> 'addr Tcp.where_to_connect
     -> (t -> 'a Deferred.t)
     -> 'a Deferred.t
-    
+
 end = struct
   type t = Rpc.Connection.t option ref
 
       if Deferred.is_determined stop then Deferred.unit
       else (
         try_with (fun () -> 
-            Tcp.connect ~interrupt:stop where_to_connect
-            >>= fun (_,r,w) ->
-            Rpc.Connection.create r w ~connection_state:()
-            >>= function
-            | Error exn -> raise exn
-            | Ok conn -> return conn            
-          )
+          Tcp.connect ~interrupt:stop where_to_connect
+          >>= fun (_,r,w) ->
+          Rpc.Connection.create r w ~connection_state:()
+          >>= function
+          | Error exn -> raise exn
+          | Ok conn -> return conn            
+        )
         >>= function
         | Error _ ->
           after reconnect_after
   let with_connect ~reconnect_after where_to_connect k =
     let stop = Ivar.create () in
     let t = create where_to_connect
-        ~reconnect_after ~stop:(Ivar.read stop)
+              ~reconnect_after ~stop:(Ivar.read stop)
     in
     Monitor.protect (fun () -> k t)
       ~finally:(fun () -> Ivar.fill stop (); Ivar.read stop)
     ~reconnect_after
     (Tcp.to_host_and_port host port)
     (fun conn -> k username conn)
-  
-    
+
+
 let retry
-    ?(retry_after=sec 10.)
-    ?(num_tries=`Unbounded)
-    ?(on_error=Fn.ignore)
-    ?(on_retry=Fn.ignore)
-    f
+      ?(retry_after=sec 10.)
+      ?(num_tries=`Unbounded)
+      ?(on_error=Fn.ignore)
+      ?(on_retry=Fn.ignore)
+      f
   =
   let rec loop tries_left = 
     f ()
         after retry_after
         >>= fun () ->
         on_retry ();
-        loop (match tries_left with
-            | `At_most n -> `At_most (n - 1)
-            | `Unbounded as x -> x)
+      loop (match tries_left with
+        | `At_most n -> `At_most (n - 1)
+        | `Unbounded as x -> x)
   in
   loop num_tries
 

client_common.mli

     -> 'addr Tcp.where_to_connect
     -> (t -> 'a Deferred.t)
     -> 'a Deferred.t
-    
+
 end
 
 val setup_robust_conn
   -> ?on_retry:(unit -> unit)
   -> (unit -> ('a,'b) Result.t Deferred.t)
   -> ('a,'b) Result.t Deferred.t
-  
+
     ( [ "-message" ; message ]
       @ [ "-title"; title ]
       @ (match sound with
-          | None -> []
-          | Some sound ->
-            [ "-sound"; (match sound with `Default -> "default" | `Path x -> x) ])
+        | None -> []
+        | Some sound ->
+          [ "-sound"; (match sound with `Default -> "default" | `Path x -> x) ])
       @ (match execute with
-          | None -> []
-          | Some command -> [ "-execute";command ])
+        | None -> []
+        | Some command -> [ "-execute";command ])
     )
 
   -> ?execute:string
   -> string  (** the message to be sent *)
   -> unit Deferred.t
-    
+
     ~summary:"Retrieve the screentime rules"
     (shared_flags ())
     (fun username () -> setup_conn username (fun username conn ->
-         Rpc.Rpc.dispatch_exn Protocol.get_rules conn username
-         >>| fun rules ->
-         printf "%s\n" (With_format.format rules)
-       ))
+       Rpc.Rpc.dispatch_exn Protocol.get_rules conn username
+       >>| fun rules ->
+       printf "%s\n" (With_format.format rules)
+     ))
 
 let edit_rules =
   Command.async_basic
     ~summary:"Set the screentime rule"
     (shared_flags ())
     (fun username () -> setup_conn username (fun username conn ->
-         Rpc.Rpc.dispatch_exn Protocol.get_rules conn username
-         >>= fun rule ->
-         let tempfile = Filename.temp_file "rule" ".scm" in
-         Writer.save tempfile ~contents:(With_format.format rule)
-         >>= fun () ->
-         let editor =
-           match Sys.getenv "EDITOR" with None -> "emacs" | Some x -> x
+       Rpc.Rpc.dispatch_exn Protocol.get_rules conn username
+       >>= fun rule ->
+       let tempfile = Filename.temp_file "rule" ".scm" in
+       Writer.save tempfile ~contents:(With_format.format rule)
+       >>= fun () ->
+       let editor =
+         match Sys.getenv "EDITOR" with None -> "emacs" | Some x -> x
+       in
+       edit_file (module Rule.List) ~editor ~tempfile
+       >>= function
+       | None -> return ()
+       | Some rules ->
+         printf "Set the rules for %s? (y/N):" (Username.to_string username);
+         Reader.read_line (Lazy.force Reader.stdin)
+         >>= fun response ->
+         let upload =
+           match response with
+           | `Eof -> false
+           | `Ok s ->
+             match s |> String.lowercase |> String.strip with
+             | "y" | "yes" -> true
+             | _ -> false
          in
-         edit_file (module Rule.List) ~editor ~tempfile
-         >>= function
-         | None -> return ()
-         | Some rules ->
-           printf "Set the rules for %s? (y/N):" (Username.to_string username);
-           Reader.read_line (Lazy.force Reader.stdin)
-           >>= fun response ->
-           let upload =
-             match response with
-             | `Eof -> false
-             | `Ok s ->
-               match s |> String.lowercase |> String.strip with
-               | "y" | "yes" -> true
-               | _ -> false
-           in
-           if not upload then
-             (printf "Not setting rules.\n"; return ())
-           else
-             Rpc.Rpc.dispatch_exn Protocol.set_rules conn (username,rules)
-             >>| fun () ->
-             printf "Rules set\n"
-       ))
+         if not upload then
+           (printf "Not setting rules.\n"; return ())
+         else
+           Rpc.Rpc.dispatch_exn Protocol.set_rules conn (username,rules)
+           >>| fun () ->
+           printf "Rules set\n"
+     ))
 
 let rule_violations =
   Command.async_basic
     ~summary:"Get any rule violations"
     (shared_flags ())
     (fun username () -> setup_conn username (fun username conn ->
-         Rpc.Rpc.dispatch_exn Protocol.todays_violations conn username
-         >>| fun violations ->
-         violations
-         |> <:sexp_of<(Rule.t * Time.Span.t * Rule_store.Status.t) list>>
-         |> Sexp.to_string_hum
-         |> printf "%s\n"
-       ))
+       Rpc.Rpc.dispatch_exn Protocol.todays_violations conn username
+       >>| fun violations ->
+       violations
+       |> <:sexp_of<(Rule.t * Time.Span.t * Rule_store.Status.t) list>>
+       |> Sexp.to_string_hum
+       |> printf "%s\n"
+     ))
 
 let violation_pipe user conn =
   let (r,w) = Pipe.create () in
   let stop = Pipe.closed r in
   Clock.every' (sec 1.) ~stop (fun () ->
-      Rpc.Rpc.dispatch_exn Protocol.todays_violations conn user
-      >>= fun violations -> 
-      if Pipe.is_closed w then Deferred.unit
-      else Pipe.write w violations);
+    Rpc.Rpc.dispatch_exn Protocol.todays_violations conn user
+    >>= fun violations -> 
+    if Pipe.is_closed w then Deferred.unit
+    else Pipe.write w violations);
   r
 
 module Full_violation = struct
         [ Column.create "rule"  (fun t -> t.rule.name |> Rule.Name.to_string)
         ; Column.create "exceeded by" (fun t -> Time.Span.to_string t.exceeded_by)
         ; Column.create "status" (fun t ->
-            match t.status with Acked -> "Ack" | Unacked -> "-")
+          match t.status with Acked -> "Ack" | Unacked -> "-")
         ; Column.create "reportable" (fun t -> Bool.to_string t.reportable)
         ]
       )
     in
     Map.merge (to_map prev) (to_map curr)
       ~f:(fun ~key:rule diff ->
-          match diff with
-          | `Left _  -> None
-          | `Right (exceeded_by,status) ->
-            Some {rule;exceeded_by;status;reportable=false}
-          | `Both ((prev_span,_),(curr_span,status)) ->
-            let reportable = 
-              match (status : Rule_store.Status.t) with
-              | Acked ->  false
-              | Unacked -> Time.Span.(curr_span > prev_span)
-            in
-            let exceeded_by = curr_span in
-            Some {rule;status;exceeded_by;reportable}
-        )
+        match diff with
+        | `Left _  -> None
+        | `Right (exceeded_by,status) ->
+          Some {rule;exceeded_by;status;reportable=false}
+        | `Both ((prev_span,_),(curr_span,status)) ->
+          let reportable = 
+            match (status : Rule_store.Status.t) with
+            | Acked ->  false
+            | Unacked -> Time.Span.(curr_span > prev_span)
+          in
+          let exceeded_by = curr_span in
+          Some {rule;status;exceeded_by;reportable}
+      )
     |> Map.data
 
   let get_pipe user conn =
 let throttle limit ~if_not_run =
   let last_time = ref Time.epoch in
   stage (fun f ->
-      let now = Time.now () in
-      let time_since =Time.diff now !last_time in
-      if Time.Span.(time_since > limit) then (
-        last_time := now;
-        f ()
-      ) else
-        if_not_run ()
-    )
+    let now = Time.now () in
+    let time_since =Time.diff now !last_time in
+    if Time.Span.(time_since > limit) then (
+      last_time := now;
+      f ()
+    ) else
+      if_not_run ()
+  )
 
 
 let monitor_violations user conn ~stop =
   Common.load_file
     For_user.t_of_sexp
     ~default:(fun () ->
-        { For_user.
-          acked = Rule.Name.Set.empty
-        ; rules = With_format.create (module Rule.List) []
-        })
+      { For_user.
+        acked = Rule.Name.Set.empty
+      ; rules = With_format.create (module Rule.List) []
+      })
     (fname t user)
 
 let save t user ruleset =
   load t user
   >>| fun for_user ->
   List.map (With_format.get for_user.rules) ~f:(fun rule ->
-      (rule, if Set.mem for_user.acked rule.name then Status.Acked else Unacked))
+    (rule, if Set.mem for_user.acked rule.name then Status.Acked else Unacked))
 
 let clear_acks_on_other_rules t user to_keep =
   load t user
 let implementations =
   let module P = Protocol in
   let (++) = Rpc.Rpc.implement in
-   [ P.start             ++ start
-   ; P.stop              ++ stop
-   ; P.status            ++ status
-   ; P.users             ++ users
-   ; P.shutdown          ++ shutdown
-   ; P.report            ++ report
-   ; P.full_report       ++ full_report
-   ; P.todays_violations ++ todays_violations
-   ; P.get_rules         ++ get_rules
-   ; P.set_rules         ++ set_rules
-   ; P.acknowledge       ++ acknowledge
-   ; P.unacknowledge     ++ unacknowledge
+  [ P.start             ++ start
+  ; P.stop              ++ stop
+  ; P.status            ++ status
+  ; P.users             ++ users
+  ; P.shutdown          ++ shutdown
+  ; P.report            ++ report
+  ; P.full_report       ++ full_report
+  ; P.todays_violations ++ todays_violations
+  ; P.get_rules         ++ get_rules
+  ; P.set_rules         ++ set_rules
+  ; P.acknowledge       ++ acknowledge
+  ; P.unacknowledge     ++ unacknowledge
   ]
 
 
        in
        create ~dir
        >>= function
-         | Error e ->
-           eprintf "Failed to start server";
-           Error.raise e
-         | Ok t ->
-           Tcp.Server.create
-             ~on_handler_error:(`Call (fun _ exn ->
-               Log.Global.sexp exn Exn.sexp_of_t))
-             (Tcp.on_port Common.port)
-             (fun _addr r w ->
-                Rpc.Connection.server_with_close r w
-                  ~implementations
-                  ~connection_state:t
-                  ~on_handshake_error:(
-                    `Call (fun exn -> Log.Global.sexp exn Exn.sexp_of_t; return ()))
-             )
-           >>= fun server ->
-           let stop = Ivar.read t.stop in
-           Deferred.any
-             [ (stop >>= fun () -> Tcp.Server.close server)
-             ; Tcp.Server.close_finished server
-             ]
+       | Error e ->
+         eprintf "Failed to start server";
+         Error.raise e
+       | Ok t ->
+         Tcp.Server.create
+           ~on_handler_error:(`Call (fun _ exn ->
+             Log.Global.sexp exn Exn.sexp_of_t))
+           (Tcp.on_port Common.port)
+           (fun _addr r w ->
+              Rpc.Connection.server_with_close r w
+                ~implementations
+                ~connection_state:t
+                ~on_handshake_error:(
+                  `Call (fun exn -> Log.Global.sexp exn Exn.sexp_of_t; return ()))
+           )
+         >>= fun server ->
+         let stop = Ivar.read t.stop in
+         Deferred.any
+           [ (stop >>= fun () -> Tcp.Server.close server)
+           ; Tcp.Server.close_finished server
+           ]
     )
 
 
     | Error exn -> Error (Error.of_exn exn)
     | Ok format ->
       match Or_error.try_with (fun () -> 
-          Sexp.of_string_conv (String.strip format) T.t_of_sexp)
+        Sexp.of_string_conv (String.strip format) T.t_of_sexp)
       with
       | Error _ as err -> err
       | Ok (`Result value) -> Ok { value; format }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.