aboutsummaryrefslogtreecommitdiff
path: root/deepenv.scm
diff options
context:
space:
mode:
Diffstat (limited to 'deepenv.scm')
-rw-r--r--deepenv.scm26
1 files changed, 19 insertions, 7 deletions
diff --git a/deepenv.scm b/deepenv.scm
index 98c9400..87a5c12 100644
--- a/deepenv.scm
+++ b/deepenv.scm
@@ -22,6 +22,8 @@
(chicken string)
(chicken process)
(chicken process-context)
+ (chicken condition)
+ (chicken format)
srfi-1
srfi-13
srfi-14)
@@ -104,11 +106,21 @@
(car executables)
program)))
-(let* ((parents (path-parents (current-directory)))
- (environment (fold .env-union '() (cons (get-environment-variables) (reverse (map load-dir-.env parents)))))
- (program (resolve-program (car (command-line-arguments))))
- (arguments (cdr (command-line-arguments))))
- (if program
- (process-execute program arguments environment)
- (display "Program not found\n")))
+(define (run-with-.env directory command arguments)
+ (let* ((parents (path-parents directory))
+ (environment (fold .env-union '() (cons (get-environment-variables) (reverse (map load-dir-.env parents)))))
+ (program (resolve-program command)))
+ (condition-case
+ (process-execute program arguments environment)
+ ((exn) (printf "Program `~a' not found!~%" command)))))
+
+(let ((not-enough-args (< (length (command-line-arguments)) 1))
+ (user-asking-help (find (lambda (item) (string=? item "--help")) (command-line-arguments))))
+ (if (or not-enough-args user-asking-help)
+ (begin
+ (display "Deepenv sources .env files in the current and parent directories, then runs a program.\n")
+ (display "Usage: deepenv <program> <arguments>\n"))
+ (run-with-.env (current-directory)
+ (car (command-line-arguments))
+ (cdr (command-line-arguments)))))