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

Commit 9b01af6

Browse files
committed
Add -main function into paos.core for cli using
1 parent 044ecc4 commit 9b01af6

File tree

5 files changed

+63
-25
lines changed

5 files changed

+63
-25
lines changed

deps.edn

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
org.clojure/data.zip {:mvn/version "0.1.2"}
44
org.reficio/soap-builder {:mvn/version "1.0.0-SNAPSHOT"}
55
selmer {:mvn/version "1.11.8"}
6-
cheshire {:mvn/version "5.8.0"}
7-
inflections {:mvn/version "0.13.0"}}
6+
inflections {:mvn/version "0.13.0"}
7+
org.clojure/tools.cli {:mvn/version "0.3.5"}}
88

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

16-
:paths ["src"]
16+
:paths ["src" "resources"]
1717

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

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

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.xapix</groupId>
55
<artifactId>paos</artifactId>
6-
<version>0.1.1</version>
6+
<version>0.1.2-SNAPSHOT</version>
77
<name>paos</name>
88
<dependencies>
99
<dependency>
@@ -31,16 +31,16 @@
3131
<artifactId>selmer</artifactId>
3232
<version>1.11.8</version>
3333
</dependency>
34-
<dependency>
35-
<groupId>cheshire</groupId>
36-
<artifactId>cheshire</artifactId>
37-
<version>5.8.0</version>
38-
</dependency>
3934
<dependency>
4035
<groupId>inflections</groupId>
4136
<artifactId>inflections</artifactId>
4237
<version>0.13.0</version>
4338
</dependency>
39+
<dependency>
40+
<groupId>org.clojure</groupId>
41+
<artifactId>tools.cli</artifactId>
42+
<version>0.3.5</version>
43+
</dependency>
4444
</dependencies>
4545
<build>
4646
<sourceDirectory>src</sourceDirectory>

src/paos/core.clj

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,59 @@
11
(ns paos.core
22
(:require [paos.wsdl :as wsdl]
3-
[clojure.pprint :refer [pprint]]
4-
[clojure.java.io :as io]
5-
[clojure.xml :as xml]
6-
[clojure.zip :as zip]
7-
[cheshire.core :as cheshire]
8-
[clojure.data.zip.xml :as zip-xml]))
3+
[paos.service :as service]
4+
[clojure.tools.cli :refer [parse-opts]]
5+
[clojure.pprint :as pprint]))
96

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

13-
(defn -main [& args]
14-
(println (cheshire/generate-string (wsdl/parse (first args)) {:pretty true})))
15-
16-
(comment
17+
(defn- help
18+
[args]
19+
(println "\nUSAGE:\n")
20+
(println "clj -m" (namespace `help) "<options>\n")
21+
(println (:summary args)))
1722

18-
(def x
19-
(wsdl/parse "resources/airlinesService.xml"))
23+
(defn- print-table [bindings]
24+
(pprint/print-table
25+
(mapcat (fn [[binding {:keys [operations]}]]
26+
(map (fn [[operation _]]
27+
{:binding binding
28+
:operation operation})
29+
operations))
30+
bindings)))
2031

21-
x)
32+
(defn -main [& args]
33+
(let [args (parse-opts args cli-options)]
34+
(if (:errors args)
35+
(do (doseq [e (:errors args)]
36+
(println e))
37+
(help args))
38+
(if (-> args :options :help)
39+
(help args)
40+
(try
41+
(let [wsdl (wsdl/parse (-> args :options :wsdl))]
42+
(if-let [binding (-> args :options :binding)]
43+
(if-let [operation (-> args :options :operation)]
44+
(let [srv (get-in wsdl [binding :operations operation])]
45+
(do
46+
(println "\nService url:\n")
47+
(println (get-in wsdl [binding :url]))
48+
(println "\nSOAP action:\n")
49+
(println (service/soap-action srv))
50+
(println "\nRequest message:\n")
51+
(println (service/request-xml srv))
52+
(println "\nResponse message:\n")
53+
(println (service/response-xml srv))))
54+
(print-table (select-keys wsdl [binding])))
55+
(print-table wsdl))
56+
(System/exit 0))
57+
(finally
58+
;; Only called if `parse` raises an exception
59+
(shutdown-agents)))))))
File renamed without changes.

0 commit comments

Comments
 (0)