Skip to content

Commit

Permalink
Handle no params case (#7)
Browse files Browse the repository at this point in the history
* fix: handle no params case
  • Loading branch information
dainiusjocas authored Mar 23, 2021
1 parent ab0f3df commit f68e5aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ NOTE: if configuration file is not provided, then empty configuration `{}` is as

## Environment variables

With environment variables only one aspect can be configured: logging level. E.g.:

With environment variables these aspects can be configured:
- Logging level. E.g.:
```shell
ROOT_LOGGER_LEVEL=WARN ./ket operation -f config.json
```
- Debug mode which prints stack traces in case of any exceptions:
```shell
DEBUG_MODE=true ./ket operation -f config.json
```
13 changes: 10 additions & 3 deletions src/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
(do
(if config-file
(throw (Exception. (format "Config file '%s' does not exists" config-file)))
(json/decode (jq/execute "{}" combined-jq-overrides)))))))
(json/decode (if (seq jq-overrides)
(jq/execute "{}" combined-jq-overrides)
"{}")))))))

(defn execute-op [operation-name options cli-operations]
(if operation-name
Expand All @@ -36,7 +38,10 @@
(println
(json/encode
(if-let [msg (if (empty? resp)
((:handler-fn operation) options)
(if (empty? options)
(throw (Exception. (format "Configuration for the operation '%s' is bad: '%s'"
(name operation-name) options)))
((:handler-fn operation) options))
resp)]
msg
(format "Operation '%s' is finished" (name operation-name))))))
Expand Down Expand Up @@ -65,7 +70,9 @@
(println (json/encode combined-conf))
(execute-op operation-name combined-conf cli-operations)))))))
(catch Exception e
(log/errorf "Failed to execute with exception: '%s'" e))))
(log/errorf "Failed to execute with exception: '%s'" e)
(when (System/getenv "DEBUG_MODE")
(.printStackTrace e)))))

(def cli-operations
(concat ops/operations ops-overrides/cli))
Expand Down

0 comments on commit f68e5aa

Please sign in to comment.