mirror of https://codeberg.org/glenneth/stash.git
Added help module and -t and -s short flags
This commit is contained in:
parent
8e717fa34b
commit
c61aa562da
|
|
@ -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 <source-dir> --target <target-dir> [options]
|
||||||
|
stash.scm -s <source-dir> -t <target-dir> [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))
|
||||||
|
|
@ -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-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-15-00] Operation cancelled by user.
|
||||||
[2024-10-04-10-18-57] 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.
|
||||||
|
|
|
||||||
38
stash.scm
38
stash.scm
|
|
@ -38,6 +38,7 @@
|
||||||
(ice-9 popen)
|
(ice-9 popen)
|
||||||
(ice-9 rdelim)
|
(ice-9 rdelim)
|
||||||
(ice-9 format)
|
(ice-9 format)
|
||||||
|
(stash-help) ;; Import the stash-help module for help functionality
|
||||||
(srfi srfi-1)
|
(srfi srfi-1)
|
||||||
(srfi srfi-19)) ;; Use for list handling and date-time formatting
|
(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
|
(let ((log-port (open-file "stash.log" "a"))) ;; Open file in append mode
|
||||||
(display (string-append "[" (current-timestamp) "] " message) log-port)
|
(display (string-append "[" (current-timestamp) "] " message) log-port)
|
||||||
(newline log-port)
|
(newline log-port)
|
||||||
(close-port log-port))) ;; Close the port after writing
|
(close-port log-port)))
|
||||||
|
|
||||||
;;; 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)))
|
|
||||||
|
|
||||||
;;; Version function
|
;;; Version function
|
||||||
(define (display-version)
|
(define (display-version)
|
||||||
|
|
@ -79,6 +73,13 @@
|
||||||
(display (format #f "Stash version ~a\n" "0.1.0-alpha.1"))
|
(display (format #f "Stash version ~a\n" "0.1.0-alpha.1"))
|
||||||
(exit 0))
|
(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
|
;;; Expand ~ in paths to the full home directory path
|
||||||
(define (expand-home path)
|
(define (expand-home path)
|
||||||
"Expand ~ to the user's home directory."
|
"Expand ~ to the user's home directory."
|
||||||
|
|
@ -86,13 +87,6 @@
|
||||||
(string-append (getenv "HOME") (substring path 1))
|
(string-append (getenv "HOME") (substring path 1))
|
||||||
path))
|
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
|
;;; Helper function to concatenate paths safely
|
||||||
(define (concat-path base path)
|
(define (concat-path base path)
|
||||||
"Concatenate two paths, ensuring there are no double slashes."
|
"Concatenate two paths, ensuring there are no double slashes."
|
||||||
|
|
@ -100,7 +94,7 @@
|
||||||
(string-append (string-drop-right base 1) "/" path)
|
(string-append (string-drop-right base 1) "/" path)
|
||||||
(string-append base "/" path)))
|
(string-append base "/" path)))
|
||||||
|
|
||||||
;;; Conflict resolution handler with backup option
|
;;; Conflict resolution handler with user options
|
||||||
(define (prompt-user-for-action)
|
(define (prompt-user-for-action)
|
||||||
"Prompt the user to decide how to handle a conflict: overwrite (o), skip (s), or cancel (c)."
|
"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))
|
(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)
|
(define (parse-arguments args)
|
||||||
"Parse command-line arguments."
|
"Parse command-line arguments."
|
||||||
(getopt-long args
|
(getopt-long args
|
||||||
'((target (value #t))
|
'((target (value #t) (single-char #\t)) ;; Support both --target and -t
|
||||||
(source (value #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
|
;;; Main entry point
|
||||||
(define (main args)
|
(define (main args)
|
||||||
"Main function to parse arguments and execute the program."
|
"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 if --version or -v was passed
|
||||||
(check-for-version args)
|
(check-for-version args)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue