File tree Expand file tree Collapse file tree
test/glojure/test_glojure Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ embedded within Go applications.
5959
6060The ` glj ` command provides a traditional Clojure development experience:
6161
62+ ** Show the help:**
63+ ```
64+ $ glj --help # or glj -h
65+ ```
66+
6267** Show the version:**
6368```
6469$ glj --version
Original file line number Diff line number Diff line change @@ -16,6 +16,27 @@ import (
1616 "github.com/glojurelang/glojure/pkg/runtime"
1717)
1818
19+ func printHelp () {
20+ fmt .Printf (`Glojure v%s
21+
22+ Usage: glj [options] [file]
23+
24+ Options:
25+ -e <expr> Evaluate expression from command line
26+ -h, --help Show this help message
27+ --version Show version information
28+
29+ Examples:
30+ glj # Start REPL
31+ glj -e "(+ 1 2)" # Evaluate expression
32+ glj script.glj # Run script file
33+ glj --version # Show version
34+ glj --help # Show this help
35+
36+ For more information, visit: https://github.com/glojurelang/glojure
37+ ` , runtime .VERSION )
38+ }
39+
1940func Main (args []string ) {
2041 runtime .AddLoadPath (os .DirFS ("." ))
2142
@@ -24,6 +45,9 @@ func Main(args []string) {
2445 } else if args [0 ] == "--version" {
2546 fmt .Printf ("glojure v%s\n " , runtime .VERSION )
2647 return
48+ } else if args [0 ] == "--help" || args [0 ] == "-h" {
49+ printHelp ()
50+ return
2751 } else if args [0 ] == "-e" {
2852 // Evaluate expression from command line
2953 if len (args ) < 2 {
Original file line number Diff line number Diff line change 99 acts like a comment and the forms are run unchanged."
1010 [purpose & test-forms]
1111 (let [tests (map
12- #(if (= (:ns (meta (resolve (first %))))
13- (the-ns 'glojure.test))
14- (concat % (list purpose))
15- %)
16- test-forms)]
12+ #(if (= (:ns (meta (resolve (first %))))
13+ (the-ns 'glojure.test))
14+ (concat % (list purpose))
15+ %)
16+ test-forms)]
1717 `(do ~@tests)))
1818
1919(defn run-cli-cmd [& args]
5454 "Version should match expected format")
5555 (is (empty? err) "Command should not return an error"))))
5656
57+ (deftest help-flag-test
58+ (test-that
59+ "glj --help flag works correctly"
60+ (let [[out err] (run-cli-cmd glj "--help")]
61+ (is (re-matches
62+ #"(?s).*Glojure v0\.3\.0.*Usage: glj.*Options:.*-e.*-h.*--help.*--version.*Examples:.*"
63+ out)
64+ "Command should output help information")
65+ (is (empty? err) "Command should not return an error"))))
66+
67+ (deftest short-help-flag-test
68+ (test-that
69+ "glj -h flag works correctly"
70+ (let [[out err] (run-cli-cmd glj "-h")]
71+ (is (re-matches
72+ #"(?s).*Glojure v0\.3\.0.*Usage: glj.*Options:.*-e.*-h.*--help.*--version.*Examples:.*"
73+ out)
74+ "Command should output help information")
75+ (is (empty? err) "Command should not return an error"))))
76+
5777(run-tests)
You can’t perform that action at this time.
0 commit comments