guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/01: bournish: Extend 'rm' command.


From: Ricardo Wurmus
Subject: 01/01: bournish: Extend 'rm' command.
Date: Thu, 26 Jan 2017 12:50:19 +0000 (UTC)

rekado pushed a commit to branch master
in repository guix.

commit 0db2ff65e7101951fedf4357aa37aaf92f7df431
Author: Ricardo Wurmus <address@hidden>
Date:   Wed Jan 25 20:52:27 2017 +0100

    bournish: Extend 'rm' command.
    
    * guix/build/bournish.scm (rm-command): New procedure.
    (%commands): Use it.
    * tests/bournish.scm: Add tests for "rm" and "rm -r".
---
 guix/build/bournish.scm |   11 ++++++++++-
 tests/bournish.scm      |   12 ++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/guix/build/bournish.scm b/guix/build/bournish.scm
index 51dad17..e948cd0 100644
--- a/guix/build/bournish.scm
+++ b/guix/build/bournish.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016 Ludovic Courtès <address@hidden>
 ;;; Copyright © 2016 Efraim Flashner <address@hidden>
+;;; Copyright © 2017 Ricardo Wurmus <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -105,6 +106,14 @@ characters."
        ((@ (guix build utils) dump-port) port (current-output-port))
        *unspecified*)))
 
+(define (rm-command . args)
+  "Emit code for the 'rm' command."
+  (cond ((member "-r" args)
+         `(for-each (@ (guix build utils) delete-file-recursively)
+                    (list ,@(delete "-r" args))))
+        (else
+         `(for-each delete-file (list ,@args)))))
+
 (define (lines+chars port)
   "Return the number of lines and number of chars read from PORT."
   (let loop ((lines 0) (chars 0))
@@ -194,7 +203,7 @@ commands such as 'ls' and 'cd'; it lacks globbing, 
pipes---everything.\n"))
   `(("echo"   ,(lambda strings `(list ,@strings)))
     ("cd"     ,(lambda (dir) `(chdir ,dir)))
     ("pwd"    ,(lambda () `(getcwd)))
-    ("rm"     ,(lambda (file) `(delete-file ,file)))
+    ("rm"     ,rm-command)
     ("cp"     ,(lambda (source dest) `(copy-file ,source ,dest)))
     ("help"   ,help-command)
     ("ls"     ,ls-command)
diff --git a/tests/bournish.scm b/tests/bournish.scm
index 0f529ce..3b40ce2 100644
--- a/tests/bournish.scm
+++ b/tests/bournish.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016 Ludovic Courtès <address@hidden>
+;;; Copyright © 2017 Ricardo Wurmus <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -38,5 +39,16 @@
   (read-and-compile (open-input-string "cd /foo\npwd\nls")
                     #:from %bournish-language #:to 'scheme))
 
+(test-equal "rm"
+  '(for-each delete-file (list "foo" "bar"))
+  (read-and-compile (open-input-string "rm foo bar\n")
+                    #:from %bournish-language #:to 'scheme))
+
+(test-equal "rm -r"
+  '(for-each (@ (guix build utils) delete-file-recursively)
+             (list "/foo" "/bar"))
+  (read-and-compile (open-input-string "rm -r /foo /bar\n")
+                    #:from %bournish-language #:to 'scheme))
+
 (test-end "bournish")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]