mirror of https://codeberg.org/glenneth/stash.git
79 lines
2.5 KiB
Scheme
79 lines
2.5 KiB
Scheme
(define-module (stash)
|
|
#:use-module (ice-9 getopt-long)
|
|
#:use-module (ice-9 ftw)
|
|
#:use-module (ice-9 rdelim)
|
|
#:use-module (stash help)
|
|
#:use-module (stash colors)
|
|
#:use-module (stash log)
|
|
#:use-module (stash paths)
|
|
#:use-module (stash conflict)
|
|
#:use-module (stash file-ops)
|
|
#:use-module (stash package)
|
|
#:use-module (stash tree)
|
|
#:use-module (srfi srfi-1)
|
|
#:use-module (srfi srfi-19)
|
|
#:export (main))
|
|
|
|
;;; Command-line options
|
|
(define %options
|
|
'((target (value #t) (single-char #\t))
|
|
(source (value #t) (single-char #\s))
|
|
(recursive (value #f) (single-char #\r))
|
|
(interactive (value #f) (single-char #\i))
|
|
(help (value #f) (single-char #\h))
|
|
(version (value #f) (single-char #\v))))
|
|
|
|
(define (main args)
|
|
"Main function to parse arguments and execute the program."
|
|
(setenv "GUILE_AUTO_COMPILE" "0")
|
|
|
|
(let* ((options (getopt-long args %options))
|
|
(help-wanted? (option-ref options 'help #f))
|
|
(source (option-ref options 'source #f))
|
|
(target (option-ref options 'target #f))
|
|
(recursive? (option-ref options 'recursive #f)))
|
|
|
|
(cond
|
|
(help-wanted?
|
|
(display-help)
|
|
(exit 0))
|
|
((and source target)
|
|
(handle-explicit-stash source target recursive?)
|
|
#t)
|
|
(else
|
|
(display-help)
|
|
(exit 1)))))
|
|
|
|
(define (handle-explicit-stash source target recursive?)
|
|
"Handle stashing with explicit source and target paths."
|
|
(let* ((source-path (canonicalize-path source))
|
|
(target-path (canonicalize-path target))
|
|
(package-name (basename source-path))
|
|
(ignore-patterns (read-ignore-patterns source-path)))
|
|
(if recursive?
|
|
(handle-recursive-stash source-path target-path)
|
|
(let ((package (make-package package-name source-path target-path ignore-patterns)))
|
|
(process-package package)
|
|
#t))))
|
|
|
|
(define (handle-recursive-stash source-path target-path)
|
|
"Handle recursive stashing of directories."
|
|
(let* ((base-name (basename source-path))
|
|
(ignore-patterns (read-ignore-patterns source-path))
|
|
(package (make-package base-name source-path target-path ignore-patterns)))
|
|
(process-package package)
|
|
#t))
|
|
|
|
(define (process-package package)
|
|
"Process a single package for stashing."
|
|
(let* ((tree (analyze-tree package))
|
|
(operations (plan-operations tree package)))
|
|
(execute-operations operations)
|
|
#t))
|
|
|
|
;; Entry point for stash
|
|
(let ((result (main (command-line))))
|
|
(if result
|
|
(exit 0)
|
|
(exit 1)))
|