Fork me on GitHub
#clojure-uk
<
2017-03-25
>
davesnowdon09:03:51

Tenuously related to REST APIs but has anyone else played with GraphQL? I came across https://github.com/walmartlabs/lacinia and it’s rekindled my interest

otfrom11:03:05

agile_geek time to start hanging out of #remote-jobs I suppose

agile_geek11:03:47

@otfrom I do but not much non permanent

otfrom11:03:32

surely a non-perm job is just one at a lower day rate and no fixed end period. 😉

otfrom11:03:41

and a one month notice

dominicm11:03:17

@davesnowdon we've been using graphql-clj in a preliminary evaluation on some projects. Definitely changes the way you build apis.

mattford20:03:12

I’ve got a clojure cli app that exits with a System/exit that does not play nice with repl.

mattford20:03:26

is there a repl friendly exit thingy?

seancorfield20:03:25

Have -main call a function to do its work. Call that from the REPL.

seancorfield20:03:38

Your -main can use the result of that function call to pick the value used in the System/exit call. This is one of those "boundary cases" where you should separate the system "side-effect" (in this case exiting the JVM) from the functional work that you code needs to perform. @mattford

mattford20:03:19

I’m actually trying to test the command line parsing

mattford20:03:06

I kinda need it to stop if if an option is not found.

mattford20:03:15

Or has bad values.

seancorfield20:03:06

Either put it in a function or just evaluate those sub-forms in the REPL.

mattford20:03:01

Basically I just copied this from the cli-api github page

mattford20:03:04

(defn -main [& args]
  (let [{:keys [options arguments errors summary]} (parse-opts args cli-options)]
    ;; Handle help and error conditions
    (cond
      (:help options) (exit 0 (usage summary))
      (not= (count arguments) 1) (exit 1 (usage summary))
      errors (exit 1 (error-msg errors)))
    ;; Execute program with options
    (case (first arguments)
      "start" (server/start! options)
      "stop" (server/stop! options)
      "status" (server/status! options)
      (exit 1 (usage summary)))))

seancorfield20:03:46

Yeah but GitHub READMEs are rarely the paragon of best practices, I'm afraid.

seancorfield21:03:09

So that's tools.cli... and parsing is already separate so what you would test here is the result of calling parse-opts, that you get the errors you expect. I guess I'm not quite sure what you're trying to do by calling -main from the REPL...

mattford21:03:52

Just test it all out

mattford21:03:27

I’ve also got nested options

mattford21:03:57

I wrapped the cond in an if.

mattford21:03:25

(it will be nil if makes it through all exit conditions)

seancorfield23:03:51

I guess I could update the tools.cli README to use an example that did not just call System/exit, since I maintain that library these days 🙂