Fix lab deploy command to properly handle switch/test/boot modes

- Updated cmd-deploy function to accept and parse mode arguments
- Added validation for deployment modes with helpful error messages
- Updated command dispatcher to pass all arguments to deploy function
- Enhanced help text with mode documentation and examples
- Fixes issue where deploy always used 'boot' mode regardless of flags

Examples now working:
- lab deploy machine switch  # Deploy and activate immediately
- lab deploy machine test    # Deploy temporarily for testing
- lab deploy machine boot    # Deploy for next boot (default)
This commit is contained in:
Geir Okkenhaug Jerstad 2025-06-26 13:39:46 +02:00
parent 27ae250fd4
commit 6306a05d64

View file

@ -28,7 +28,8 @@ USAGE: lab <command> [args...]
COMMANDS: COMMANDS:
status Show infrastructure status status Show infrastructure status
machines List all machines machines List all machines
deploy <machine> Deploy configuration to machine deploy <machine> [mode] Deploy configuration to machine
Available modes: boot (default), test, switch
deploy-all Deploy to all machines deploy-all Deploy to all machines
update Update flake inputs update Update flake inputs
health [machine] Check machine health (all if no machine specified) health [machine] Check machine health (all if no machine specified)
@ -39,7 +40,9 @@ COMMANDS:
EXAMPLES: EXAMPLES:
lab status lab status
lab machines lab machines
lab deploy congenital-optimist lab deploy congenital-optimist # Deploy with boot mode (default)
lab deploy congenital-optimist switch # Deploy and activate immediately
lab deploy congenital-optimist test # Deploy temporarily for testing
lab deploy-all lab deploy-all
lab update lab update
lab health lab health
@ -100,17 +103,24 @@ Home lab root: ~a
(format #t "Configured Machines:\n~a\n" machine-list) (format #t "Configured Machines:\n~a\n" machine-list)
(log-success "Machine list complete"))) (log-success "Machine list complete")))
(define (cmd-deploy machine-name) (define (cmd-deploy machine-name . args)
"Deploy configuration to machine" "Deploy configuration to machine"
(log-info "Deploying to machine: ~a" machine-name) (let* ((mode (if (null? args) "boot" (car args)))
(if (validate-machine-name machine-name) (valid-modes '("boot" "test" "switch")))
(let ((result (deploy-machine machine-name "boot" '()))) (log-info "Deploying to machine: ~a (mode: ~a)" machine-name mode)
(if result (if (not (member mode valid-modes))
(log-success "Deployment to ~a complete" machine-name) (begin
(log-error "Deployment to ~a failed" machine-name))) (log-error "Invalid deployment mode: ~a" mode)
(begin (log-error "Valid modes: ~a" (string-join valid-modes ", "))
(log-error "Invalid machine: ~a" machine-name) (format #t "Usage: lab deploy <machine> [boot|test|switch]\n"))
(log-info "Available machines: ~a" (string-join (get-all-machines) ", "))))) (if (validate-machine-name machine-name)
(let ((result (deploy-machine machine-name mode '())))
(if result
(log-success "Deployment to ~a complete (mode: ~a)" machine-name mode)
(log-error "Deployment to ~a failed" machine-name)))
(begin
(log-error "Invalid machine: ~a" machine-name)
(log-info "Available machines: ~a" (string-join (get-all-machines) ", ")))))))
(define (cmd-ssh machine-name) (define (cmd-ssh machine-name)
"SSH to machine" "SSH to machine"
@ -209,8 +219,8 @@ Home lab root: ~a
(if (null? args) (if (null? args)
(begin (begin
(log-error "deploy command requires machine name") (log-error "deploy command requires machine name")
(format #t "Usage: lab deploy <machine>\n")) (format #t "Usage: lab deploy <machine> [boot|test|switch]\n"))
(cmd-deploy (car args)))) (apply cmd-deploy args)))
('deploy-all ('deploy-all
(cmd-deploy-all)) (cmd-deploy-all))