#! /usr/local/bin/guile \
-e main
!#

;;  -*-  indent-tabs-mode:nil; coding: utf-8 -*-
;;  Copyright (C) 2015
;;      "Mu Lei" known as "NalaGinrut" <NalaGinrut@gmail.com>
;;  Artanis is free software: you can redistribute it and/or modify
;;  it under the terms of the GNU General Public License and GNU
;;  Lesser General Public License published by the Free Software
;;  Foundation, either version 3 of the License, or (at your option)
;;  any later version.

;;  Artanis is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU General Public License and GNU Lesser General Public License
;;  for more details.

;;  You should have received a copy of the GNU General Public License
;;  and GNU Lesser General Public License along with this program.
;;  If not, see <http://www.gnu.org/licenses/>.

(setlocale LC_ALL "")
(use-modules (ice-9 getopt-long)
             (artanis commands)
             (artanis commands help))

(define main
  (lambda (args)
    (cond
     ((find-command (if (no-command? args) "help" (cadr args)))
      => (lambda (mod)
           (exit (apply (module-ref mod 'main) (if (no-command-args? args)
                                                   '()
                                                   (cddr args))))))
     (else
      (format (current-error-port)
              "art: unknown command ~s~%" (cadr args))
      (format (current-error-port)
              "Try `art help' for more information.~%")
      (exit 1)))))
