Commits

Yaron Minsky committed 4c48507

removed core_extended dep

Comments (0)

Files changed (5)

_tags

-true: syntax(camlp4o)
-true: package(core,sexplib.syntax,bin_prot.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax,async,core_extended)
-true: thread,debug,annot
 open Core.Std
 open Async.Std
 open Broker_protocol
-module Ascii_table = Core_extended.Std.Ascii_table
-
-let shell cmd args =
-  In_thread.run (fun () ->
-    try Ok (Core_extended.Shell.run_full cmd args)
-    with exn -> Error exn)
+module Ascii_table = Textutils.Std.Ascii_table
 
 let shutdown =
   Common.with_rpc_conn (fun conn ->
 
 let publish ~topic ~text =
   Common.with_rpc_conn (fun conn ->
-    shell "whoami" []
-    >>= fun username ->
-    let username = Result.ok_exn username in
-    let from = Username.of_string (String.strip username) in
+    let from =
+      Option.value_exn (Sys.getenv "USER") ~message:"Unknown username"
+      |> String.strip
+      |> Username.of_string
+    in
     Rpc.Rpc.dispatch_exn publish_rpc conn
       { Message.
         text; topic; from; time = Time.now () }
   )
 
-let pub_cmd = Command.async_basic
-  ~summary:"publish a single value"
-  Command.Spec.(
-    (host_and_port ())
-    +> anon ("<topic>" %: Arg_type.create Topic.of_string)
-    +> anon ("<text>" %: string)
-  )
-  (fun host port topic text () -> publish ~host ~port ~topic ~text)
+let pub_cmd =
+  Command.async_basic
+    ~summary:"publish a single value"
+    Command.Spec.(
+      (host_and_port ())
+      +> anon ("<topic>" %: Arg_type.create Topic.of_string)
+      +> anon ("<text>" %: string)
+    )
+    (fun host port topic text () -> publish ~host ~port ~topic ~text)
 
 let subscribe ~topic =
   Common.with_rpc_conn (fun conn ->
-    shell "clear" []
-    >>= fun clear_string ->
-    let clear_string =
-      (* if we're not on a terminal, just use the empty string *)
-      match clear_string with
-      | Ok s -> s | Error _ -> ""
-    in
+    let clear_string = "\027[H\027[2J" in
     Rpc.Pipe_rpc.dispatch subscribe_rpc conn topic
     >>= function
     | Error err -> Error.raise err
         return ()
       ))
 
-let sub_cmd = Command.async_basic
-  ~summary:"subscribe to a topic"
-  Command.Spec.(
-    host_and_port ()
-    +> anon ("<topic>" %: Arg_type.create Topic.of_string)
-  )
-  (fun host port topic () -> subscribe ~host ~port ~topic)
+let sub_cmd =
+  Command.async_basic
+    ~summary:"subscribe to a topic"
+    Command.Spec.(
+      host_and_port ()
+      +> anon ("<topic>" %: Arg_type.create Topic.of_string)
+    )
+    (fun host port topic () -> subscribe ~host ~port ~topic)
 
 let sexp_print_dump dump =
   printf "%s\n"
   type t = single list with sexp,bin_io, compare
 end
 
-let publish_rpc = Rpc.Rpc.create
-  ~name:"publish"
-  ~version:0
-  ~bin_query:Message.bin_t
-  ~bin_response:Unit.bin_t
+let publish_rpc =
+  Rpc.Rpc.create
+    ~name:"publish"
+    ~version:0
+    ~bin_query:Message.bin_t
+    ~bin_response:Unit.bin_t
 
-let subscribe_rpc = Rpc.Pipe_rpc.create
-  ~name:"subscribe"
-  ~version:0
-  ~bin_query:Topic.bin_t
-  ~bin_response:Message.bin_t
-  ~bin_error:String.bin_t
+let subscribe_rpc =
+  Rpc.Pipe_rpc.create
+    ~name:"subscribe"
+    ~version:0
+    ~bin_query:Topic.bin_t
+    ~bin_response:Message.bin_t
+    ~bin_error:String.bin_t
 
-let dump_rpc = Rpc.Rpc.create
-  ~name:"dump"
-  ~version:0
-  ~bin_query:Unit.bin_t
-  ~bin_response:Dump.bin_t
+let dump_rpc =
+  Rpc.Rpc.create
+    ~name:"dump"
+    ~version:0
+    ~bin_query:Unit.bin_t
+    ~bin_response:Dump.bin_t
 
-let shutdown_rpc = Rpc.Rpc.create
-  ~name:"shutdown"
-  ~version:0
-  ~bin_query:Unit.bin_t
-  ~bin_response:Unit.bin_t
+let shutdown_rpc =
+  Rpc.Rpc.create
+    ~name:"shutdown"
+    ~version:0
+    ~bin_query:Unit.bin_t
+    ~bin_response:Unit.bin_t
 
-let clear_rpc = Rpc.Rpc.create
-  ~name:"clear"
-  ~version:0
-  ~bin_query:Topic.bin_t
-  ~bin_response:Unit.bin_t
+let clear_rpc =
+  Rpc.Rpc.create
+    ~name:"clear"
+    ~version:0
+    ~bin_query:Topic.bin_t
+    ~bin_response:Unit.bin_t
 
 (* Finally we create a command for starting the broker server *)
 
-let command = Command.async_basic
+let command =
+  Command.async_basic
   ~summary:"Start the message broker server"
   Command.Spec.(
     empty
 
 EXT=native
 
-corebuild -j 4  \
+corebuild \
+    -j 4 \
+    -pkg async,textutils  \
     hello_world.$EXT \
     hello_client.$EXT \
     hello_server.$EXT \