Giter VIP home page Giter VIP logo

remote-repl's Introduction

Remote repl

Clojars Project

Rationale

Sometimes I want to open a remote socket repl from my repl, but Clojure does not provide a way to do this out of the box.

Usage

To give it a try, you need a socket repl available on the network. You can start it with this shell command:

$ clj "-J-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}" 

Now you can connect to that process from another process

$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}'
Clojure 1.10.1
user=> (require '[vlaaad.remote-repl :as rr])
nil
user=> (rr/repl :port 5555)
;; at this point, forms sent to the repl are evaluated on the remote process 
user=> (System/getProperty "clojure.server.repl")
"{:port 5555 :accept clojure.core.server/repl}"
user=> :repl/quit
;; now we are back to evaluating in our local process.
nil
user=> 

You can use -main to immediately drop into a remote repl:

$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}' -m vlaaad.remote-repl :port 5555
user=> (System/getProperty "clojure.server.repl")
"{:port 5555 :accept clojure.core.server/repl}"
user=> :repl/quit

You can use -X style invocation:

$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}' -X vlaaad.remote-repl/repl :port 5555

You can install remote repl as a tool:

clj -Ttools install \
  vlaaad/remote-repl '{:git/url "https://github.com/vlaaad/remote-repl.git" :git/tag "v1.2.12"}' \
  :as remote-repl
clj -Tremote-repl repl :port 5555

Reconnecting

It might be useful to automatically reconnect to the remote REPL. For example, you might want to restart your REPL server during development to update dependencies. You can use :reconnect true option to keep the REPL client reconnecting, that way it will keep connecting to the remote REPL while the JVM is alive.

Example:

$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.2.12"}}}' \
  -X vlaaad.remote-repl/repl \
  :port 5757 :reconnect true
Reconnecting to localhost:5757
Reconnecting to localhost:5757
...

Then, start a REPL server on port 5757 in a different terminal:

$ clj -J-Dclojure.server.repl='{:port 5555 :accept clojure.core.server/repl}'

Once it starts, first terminal will establish the connection:

...
Reconnecting to localhost:5757
Reconnecting to localhost:5757
user=> 

Acknowledgements

This project is similar to tubular, but smaller (only 70 lines of code and no dependencies). It is inspired by clojure.core.server/remote-prepl, but does not require its target to be a prepl.

remote-repl's People

Contributors

vlaaad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

remote-repl's Issues

How to evaluate in remote REPL and use output in local REPL?

This is possibly out of scope for this project but I'm curious to hear your ideas.

Concrete Example
I often use embedded databases (e.g. Datalevin). In production the way I access these from my local dev env is through a remote socket repl. So far so good. Often I want to pull some datoms or the whole DB from prod to test with locally. The way I've been doing this thus far is by scp'ing the entire prod DB onto my machine. But this can take a long time with a large DB. Often I just want part of it. Is there a way to have more of an RPC-like experience where I can run a query in the remote repl but get the output in my local repl such that I can write it to disk or transact it into another DB?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.