summaryrefslogtreecommitdiff
path: root/find-version.sh
blob: 99aa538aeabce071a5690e8e7e34f08439704fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-

(with-temp-buffer
  ;; the version information is stored in the Cargo.toml file.
  (insert-file-contents "Cargo.toml")
  (goto-char (point-min))
  (cond
   ;; search for the version assignment statement
   ((search-forward "version =" nil t)
    ;; skip spaces
    (re-search-forward "[[:space:]]*" (line-end-position) t)
    ;; check it starts with a double quote
    (cond
     ((= (char-after) 34))
     ((error "Invalid syntax at %d" (point))))
    (let ((end (line-end-position)))
      ;; and check it ends with a double quote as well
      (cond
       ((= (char-before end) 34))
       ((error "Invalid syntax at %d" (1- end))))
      ;; then print the bare version string out without delimiters
      (princ
       (buffer-substring-no-properties
        (1+ (point)) (1- end)))))
   ((print "Unknown"))))