Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Add -main function into paos.core for cli using
Browse files Browse the repository at this point in the history
  • Loading branch information
DeLaGuardo committed Jul 15, 2018
1 parent 044ecc4 commit 9b01af6
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 25 deletions.
8 changes: 4 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
org.clojure/data.zip {:mvn/version "0.1.2"}
org.reficio/soap-builder {:mvn/version "1.0.0-SNAPSHOT"}
selmer {:mvn/version "1.11.8"}
cheshire {:mvn/version "5.8.0"}
inflections {:mvn/version "0.13.0"}}
inflections {:mvn/version "0.13.0"}
org.clojure/tools.cli {:mvn/version "0.3.5"}}

:mvn/repos {"reficio" {:url "http://repo.reficio.org/maven/"}
"soapui" {:url "http://www.soapui.org/repository/maven2"}
Expand All @@ -13,14 +13,14 @@
"clojars" {:url "https://clojars.org/repo/"}
"sonatype" {:url "https://oss.sonatype.org/content/repositories/snapshots/"}}

:paths ["src"]
:paths ["src" "resources"]

:aliases
{:1.8 {:override-deps {org.clojure/clojure {:mvn/version "1.8.0"}}}
:1.9 {:override-deps {org.clojure/clojure {:mvn/version "1.9.0"}}}
:master {:override-deps {org.clojure/clojure {:mvn/version "1.10.0-master-SNAPSHOT"}}}

:test {:extra-paths ["test" "resources"]
:test {:extra-paths ["test" "test_resources"]
:extra-deps {org.clojure/test.check {:mvn/version "RELEASE"}
clj-http {:mvn/version "3.9.0"}}}

Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.xapix</groupId>
<artifactId>paos</artifactId>
<version>0.1.1</version>
<version>0.1.2-SNAPSHOT</version>
<name>paos</name>
<dependencies>
<dependency>
Expand Down Expand Up @@ -31,16 +31,16 @@
<artifactId>selmer</artifactId>
<version>1.11.8</version>
</dependency>
<dependency>
<groupId>cheshire</groupId>
<artifactId>cheshire</artifactId>
<version>5.8.0</version>
</dependency>
<dependency>
<groupId>inflections</groupId>
<artifactId>inflections</artifactId>
<version>0.13.0</version>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>tools.cli</artifactId>
<version>0.3.5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
68 changes: 53 additions & 15 deletions src/paos/core.clj
Original file line number Diff line number Diff line change
@@ -1,21 +1,59 @@
(ns paos.core
(:require [paos.wsdl :as wsdl]
[clojure.pprint :refer [pprint]]
[clojure.java.io :as io]
[clojure.xml :as xml]
[clojure.zip :as zip]
[cheshire.core :as cheshire]
[clojure.data.zip.xml :as zip-xml]))
[paos.service :as service]
[clojure.tools.cli :refer [parse-opts]]
[clojure.pprint :as pprint]))

(defn decompose-wsdl [wsdl-path]
(wsdl/parse wsdl-path))
(def cli-options
[["-w" "--wsdl WSDL" "Url or filesystem path or a content of wsdl. (Required)"
:parse-fn str
:validate [#(string? (not-empty %)) "Must be a non-empty string."]]
["-b" "--binding BINDING" "One of SOAP binding defined in WSDL."
:parse-fn str]
["-o" "--operation OPERATION" "One of SOAP operation defined for given WSDL binding. Can not be used without binding."
:parse-fn str]
["-h" "--help" "Display this help message"]])

(defn -main [& args]
(println (cheshire/generate-string (wsdl/parse (first args)) {:pretty true})))

(comment
(defn- help
[args]
(println "\nUSAGE:\n")
(println "clj -m" (namespace `help) "<options>\n")
(println (:summary args)))

(def x
(wsdl/parse "resources/airlinesService.xml"))
(defn- print-table [bindings]
(pprint/print-table
(mapcat (fn [[binding {:keys [operations]}]]
(map (fn [[operation _]]
{:binding binding
:operation operation})
operations))
bindings)))

x)
(defn -main [& args]
(let [args (parse-opts args cli-options)]
(if (:errors args)
(do (doseq [e (:errors args)]
(println e))
(help args))
(if (-> args :options :help)
(help args)
(try
(let [wsdl (wsdl/parse (-> args :options :wsdl))]
(if-let [binding (-> args :options :binding)]
(if-let [operation (-> args :options :operation)]
(let [srv (get-in wsdl [binding :operations operation])]
(do
(println "\nService url:\n")
(println (get-in wsdl [binding :url]))
(println "\nSOAP action:\n")
(println (service/soap-action srv))
(println "\nRequest message:\n")
(println (service/request-xml srv))
(println "\nResponse message:\n")
(println (service/response-xml srv))))
(print-table (select-keys wsdl [binding])))
(print-table wsdl))
(System/exit 0))
(finally
;; Only called if `parse` raises an exception
(shutdown-agents)))))))
File renamed without changes.

0 comments on commit 9b01af6

Please sign in to comment.