-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add cli entry point for ide #340
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,97 @@ | ||
(ns etaoin.ide.main | ||
(:require [etaoin.api :refer :all] | ||
[etaoin.ide.flow :refer [run-ide-script]]) | ||
(:gen-class)) | ||
(:require [clojure.java.io :as io] | ||
[clojure.string :as str] | ||
[clojure.tools.cli :refer [parse-opts]] | ||
[etaoin.api :as api] | ||
[etaoin.ide.flow :as flow] | ||
[etaoin.util :refer [exit]]) | ||
(:gen-class)) | ||
|
||
(def browsers-set | ||
#{:chrome :safari :firefox :edge :phantom}) | ||
|
||
(defn -main | ||
[& args]) | ||
(defn str->vec | ||
[string] | ||
(str/split string #",")) | ||
|
||
(def cli-options | ||
[["-d" "--driver-name name" "The name of driver. The default is `chrome`" | ||
:default :chrome | ||
:parse-fn keyword | ||
:validate [browsers-set | ||
(str "Must be one of the list items - " (str/join ", " (map name browsers-set)))]] | ||
|
||
["-p" "--params params" "Parameters for the driver represented as edn string" | ||
:default {} | ||
:parse-fn read-string] | ||
|
||
["-f" "--file path" "Path to the ide file on disk"] | ||
|
||
["-r" "--resource path" "Path to the resource"] | ||
|
||
[nil "--test-ids ids" "Comma-separeted test ID(s)" | ||
:parse-fn str->vec] | ||
|
||
[nil "--suite-ids ids" "Comma-separeted suite ID(s)" | ||
:parse-fn str->vec] | ||
|
||
[nil "--test-names names" "Comma-separeted test name(s)" | ||
:parse-fn str->vec] | ||
|
||
[nil "--suite-names names" "Comma-separeted suite name(s)" | ||
:parse-fn str->vec] | ||
|
||
[nil "--base-url url" "Base url for test"] | ||
["-h" "--help"]]) | ||
|
||
(def help | ||
"This is cli interface for running ide files. | ||
|
||
Usage examples: | ||
|
||
lein run -m etaoin.ide.main -d firefox -p '{:port 8888 :args [\"--no-sandbox\"]} -r ide/test.side | ||
|
||
java -cp .../poject.jar -m etaoin.ide.main -d firefox -p '{:port 8888} -f ide/test.side | ||
|
||
Options:") | ||
|
||
(defn usage [options-summary] | ||
(->> [help options-summary] | ||
(str/join \newline))) | ||
|
||
(defn error-msg [errors] | ||
(str "The following errors occurred while parsing your command:\n\n" | ||
(str/join \newline errors))) | ||
|
||
(defn run-script | ||
[file-path {:keys [driver-name params] :as options}] | ||
(let [opt (select-keys options [:base-url :test-ids | ||
:test-names :suite-ids | ||
:suite-names])] | ||
(api/with-driver driver-name params driver | ||
(flow/run-ide-script driver file-path opt)))) | ||
|
||
(defn -main [& args] | ||
(let [{:keys [errors summary options]} (parse-opts args cli-options) | ||
{:keys [help file resource]} options] | ||
(cond | ||
errors | ||
(exit 1 (error-msg errors)) | ||
|
||
help | ||
(exit 0 (usage summary)) | ||
|
||
file | ||
(let [ide-file (io/file file)] | ||
(when-not (and (.exists ide-file) | ||
(not (.isDirectory ide-file))) | ||
(exit 1 "The IDE file not found")) | ||
(run-script file options)) | ||
|
||
resource | ||
(if-let [r (io/resource resource)] | ||
(run-script (str r) options) | ||
(exit 1 "Resource not found")) | ||
|
||
:else | ||
(exit 1 "Specify the path to the ide file: `--file` or `--resource`")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
здесь и ниже: немного странно, что в обоих случаях мы передаем в
run-script
файл и ресурс как строку. В этом случае низлежащийio/reader
трактует строку как путь к файлу, то есть с ресурсами из jar это работать не будет. Лучше передаватьide-file
иr
в run-script. Оба будут прочитаны корректно с помощьюio/reader
.Тогда первый параметр в
run-script
лучше назвать source, источник -- все, что может бытьslurp
-нуто. И в низлежащейrun-ide-script
тоже переименовать парамерт и просто сделатьslurp
на нем.