diff --git a/stash-help.scm b/stash-help.scm new file mode 100644 index 0000000..b9f4275 --- /dev/null +++ b/stash-help.scm @@ -0,0 +1,30 @@ +;; stash-help.scm --- Help message module for Stash + +(define-module (stash-help) + #:export (display-help)) + +;;; Function to display help message +(define (display-help) + "Display help message explaining how to use the program." + (display " +Usage: stash.scm --source --target [options] + stash.scm -s -t [options] + +Stash is a Guile Scheme utility for moving directories and creating symlinks with conflict resolution. + +Options: + --source, -s Specify the source directory to be moved. + --target, -t Specify the target directory where the symlink should be created. + --version, -v Show the current version of the program. + --help, -h Display this help message. + +Examples: + Using long options: + guile -L . stash.scm --source ~/.config/test --target ~/.dotfiles/ + + Using short options (without `=`): + guile -L . stash.scm -s ~/.config/test -t ~/.dotfiles/ + +This command will move the directory ~/.config/test to ~/.dotfiles/.config/test and create a symlink in ~/.config pointing to the new location. +") + (exit 0)) diff --git a/stash.log b/stash.log index b70b187..d061036 100644 --- a/stash.log +++ b/stash.log @@ -56,3 +56,12 @@ Symlink created at /home/glenn/.config/test pointing to /home/glenn/.dotfiles/.c [2024-10-04-10-14-57] Symlink created at /home/glenn/.config/test pointing to /home/glenn/.dotfiles/.config/test [2024-10-04-10-15-00] Operation cancelled by user. [2024-10-04-10-18-57] Operation cancelled by user. +[2024-10-04-12-40-06] Moved /home/glenn/.config/test to /home/glenn/.dotfiles/.config/test +[2024-10-04-12-40-06] Symlink created at /home/glenn/.config/test pointing to /home/glenn/.dotfiles/.config/test +[2024-10-04-12-40-11] Operation cancelled by user. +[2024-10-04-12-43-41] Moved /home/glenn/.config/test to /home/glenn/.dotfiles/.config/test +[2024-10-04-12-43-41] Symlink created at /home/glenn/.config/test pointing to /home/glenn/.dotfiles/.config/test +[2024-10-04-12-43-45] Operation cancelled by user. +[2024-10-04-12-46-28] Operation cancelled by user. +[2024-10-04-12-46-43] Skipped moving directory: /home/glenn/.dotfiles/.config/test +[2024-10-04-12-46-48] Operation cancelled by user. diff --git a/stash.scm b/stash.scm index 83368f1..546909b 100644 --- a/stash.scm +++ b/stash.scm @@ -38,6 +38,7 @@ (ice-9 popen) (ice-9 rdelim) (ice-9 format) + (stash-help) ;; Import the stash-help module for help functionality (srfi srfi-1) (srfi srfi-19)) ;; Use for list handling and date-time formatting @@ -64,14 +65,7 @@ (let ((log-port (open-file "stash.log" "a"))) ;; Open file in append mode (display (string-append "[" (current-timestamp) "] " message) log-port) (newline log-port) - (close-port log-port))) ;; Close the port after writing - -;;; Helper function to check for --version and -v before argument parsing -(define (check-for-version args) - "Check if --version or -v is in the arguments list." - (if (or (member "--version" args) - (member "-v" args)) - (display-version))) + (close-port log-port))) ;;; Version function (define (display-version) @@ -79,6 +73,13 @@ (display (format #f "Stash version ~a\n" "0.1.0-alpha.1")) (exit 0)) +;;; Helper function to check for version flag and display version +(define (check-for-version args) + "Check if --version or -v is in the arguments list." + (if (or (member "--version" args) + (member "-v" args)) + (display-version))) + ;;; Expand ~ in paths to the full home directory path (define (expand-home path) "Expand ~ to the user's home directory." @@ -86,13 +87,6 @@ (string-append (getenv "HOME") (substring path 1)) path)) -;;; Helper function to quote shell arguments -(define (shell-quote-argument arg) - "Quote shell argument to handle spaces or special characters." - (if (string-contains arg " ") - (string-append "\"" (string-replace arg "\"" "\\\"") "\"") - arg)) - ;;; Helper function to concatenate paths safely (define (concat-path base path) "Concatenate two paths, ensuring there are no double slashes." @@ -100,7 +94,7 @@ (string-append (string-drop-right base 1) "/" path) (string-append base "/" path))) -;;; Conflict resolution handler with backup option +;;; Conflict resolution handler with user options (define (prompt-user-for-action) "Prompt the user to decide how to handle a conflict: overwrite (o), skip (s), or cancel (c)." (display (color-message "A conflict was detected. Choose action - Overwrite (o), Skip (s), or Cancel (c): " yellow-text)) @@ -208,13 +202,19 @@ (define (parse-arguments args) "Parse command-line arguments." (getopt-long args - '((target (value #t)) - (source (value #t))))) + '((target (value #t) (single-char #\t)) ;; Support both --target and -t + (source (value #t) (single-char #\s)) ;; Support both --source and -s + (help (value #f) (single-char #\h)) ;; Support -h for help + (version (value #f) (single-char #\v))))) ;; Support -v for version ;;; Main entry point (define (main args) "Main function to parse arguments and execute the program." - (setenv "GUILE_AUTO_COMPILE" "0") ;; Disable auto-compilation to improve performance + (setenv "GUILE_AUTO_COMPILE" "0") + ;; Check if --help or -h was passed + (if (or (member "--help" args) (member "-h" args)) + (display-help)) + ;; Check if --version or -v was passed (check-for-version args)