-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from yetanalytics/cli-subcommands
[DS-152] CLI subcommands
- Loading branch information
Showing
10 changed files
with
505 additions
and
328 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(ns com.yetanalytics.datasim.cli | ||
(:require [clojure.tools.cli :as cli] | ||
[com.yetanalytics.datasim.cli.input :as cli-input] | ||
[com.yetanalytics.datasim.cli.generate :as cli-gen] | ||
[com.yetanalytics.datasim.cli.util :as u]) | ||
(:gen-class)) | ||
|
||
(def top-level-options | ||
[["-h" "--help" "Display the top-level help guide."]]) | ||
|
||
(def top-level-summary | ||
(str "Usage: 'datasim <subcommand> <args>' or 'datasim [-h|--help]'.\n" | ||
"\n" | ||
"where the subcommand can be one of the following:\n" | ||
" validate-input: Validate the input and create an input JSON file.\n" | ||
" generate: Generate statements from input and print to stdout.\n" | ||
" generate-post: Generate statements from input and POST them to an LRS.\n" | ||
"\n" | ||
"Run 'datasim <subcommand> --help' for more info on each subcommand.")) | ||
|
||
(defn -main [& args] | ||
(let [{:keys [options arguments summary errors]} | ||
(cli/parse-opts args top-level-options | ||
:in-order true | ||
:summary-fn (fn [_] top-level-summary)) | ||
[subcommand & rest-args] | ||
arguments] | ||
(cond | ||
(:help options) | ||
(println summary) | ||
(not subcommand) | ||
(print "No subcommand entered.\n\n" summary) | ||
:else | ||
(case subcommand | ||
"validate-input" (cli-input/validate-input rest-args) | ||
"generate" (cli-gen/generate rest-args) | ||
"generate-post" (cli-gen/generate-post rest-args) | ||
(u/bail! errors))))) |
Oops, something went wrong.