Browse Source

Added functionality to bulk-edit records

Samuel W. Flint 7 years ago
parent
commit
cd20b65156
1 changed files with 25 additions and 2 deletions
  1. 25 2
      library.org

+ 25 - 2
library.org

@@ -100,6 +100,10 @@ As a person who has a lot of books, I like to be able to keep track of them.  I'
           do_edit $@
           exit
           ;;
+      edit-matching)
+          do_edit_exp "$@"
+          exit
+          ;;
       loan)
            do_loan $@
            exit
@@ -392,6 +396,24 @@ This handles git as needed, by first checking to see if the first argument is ~i
       do_git add `basename ${LIBRARYFILE}`
       do_git commit -m "Edited record id ${ID}"
   }
+
+  function do_edit_exp {
+      if [[ $# -lt 3 ]] ; then
+          echo "ledger edit-matching match-exp field value"
+          exit 1
+      fi
+      MATCHEXPRESSION=$1
+      shift
+      FIELDNAME=$1
+      shift
+      VALUE=$1
+      shift
+      recset -e "${MATCHEXPRESSION}" \
+             -f "${FIELDNAME}" -S "${VALUE}" \
+             ${LIBRARYFILE}
+      do_git add $(basename ${LIBRARYFILE})
+      do_git commit -m "Edited records"
+  }
 #+END_SRC
 
 * WORKING Loan
@@ -458,13 +480,13 @@ To complete this program, I include a help message, a small part of which is dis
 #+Name: help-message
 #+BEGIN_SRC sh
   if [[ $# -eq 0 ]] ; then
-      echo "library [ help | query | add | git | bulk-add | report | edit | loan | return-book | init ]"
+      echo "library [ help | query | add | git | bulk-add | report | edit | edit-matching | loan | return-book | init ]"
       exit
   fi
 
   function display_help {
       cat <<EOF
-  library [ help | query | add | git | bulk-add | report | edit | loan | return-book | init ]
+  library [ help | query | add | git | bulk-add | report | edit | edit-matching | loan | return-book | init ]
 
   help:       Display this help message.
   query:      Query Library Database.
@@ -473,6 +495,7 @@ To complete this program, I include a help message, a small part of which is dis
   bulk-add:   Add a specified number of records.
   report:     Run a report.
   edit:       Edit the value of a specified field in a specified record.
+  edit-matching: Edit records matching a give expression
   loan:       Loan a book out.
   return-book:Process a book return
   init:       Initialize the database.