Skip to content

Commit

Permalink
Added args
Browse files Browse the repository at this point in the history
  • Loading branch information
KikyTokamuro committed Aug 17, 2021
1 parent 40cc5f2 commit c9f6018
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions fetch.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/guile
#!/usr/bin/guile \
-e main -s
!#

;; System information fetcher written in GNU Guile Scheme
;; https://github.com/KikyTokamuro/fetch.scm

;; MIT License

;; Copyright (c) 2021 Kiky Tokamuro (Daniil Archangelsky)
Expand All @@ -26,7 +30,8 @@
(use-modules (ice-9 format)
(ice-9 rdelim)
(ice-9 regex)
(ice-9 popen))
(ice-9 popen)
(ice-9 getopt-long))

(define (run-cmd cmd)
"Run command and return output"
Expand Down Expand Up @@ -95,7 +100,6 @@
(define (get-distro)
"Return distro name"
(cond ((file-exists? "/etc/os-release") (os-release-name "/etc/os-release"))
((file-exists? "/usr/lib/os-release") (os-release-name "/usr/lib/os-release"))
((which "lsb_release") (string-trim-both (run-cmd "lsb_release -sd") #\"))
((which "uname") (run-cmd "uname -o"))
(else "unknown")))
Expand All @@ -121,4 +125,21 @@
(format #t "~18a -> ~a\n" (green "uptime") uptime)
(format #t "~18a -> ~a\n" (green "shell") shell)))

(print-info)
(define help-message "fetch.scm - system information fetcher\n
fetch.scm [options]
-v, --version Display version
-h, --help Display this help")

(define version-message "fetch.scm v0.1.3")

(define (main args)
(let* ((option-spec '((version (single-char #\v) (value #f))
(help (single-char #\h) (value #f))))
(options (getopt-long args option-spec))
(help-wanted (option-ref options 'help #f))
(version-wanted (option-ref options 'version #f)))
(if (or version-wanted help-wanted)
(begin
(if version-wanted (format #t "~a\n" version-message))
(if help-wanted (format #t "~a\n" help-message)))
(print-info))))

0 comments on commit c9f6018

Please sign in to comment.