;; -*-theme-*-

;; Copyright (C) 2022 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

;; Expected results: translation and running OK


(define-proper-program (examples command-line-demo)

  (import (standard-library core)
	  (standard-library command-line-parser)
	  (standard-library list-utilities)
	  (standard-library console-io))

  (define-main-proc (((l-args (:uniform-list <string>))) <none> nonpure)
    (let-mutable ((str-output-file <string> "")
		  (b-flag <boolean> #f)
		  (str-input-file <string> ""))
      (let* ((argdesc1
	      (create <argument-descriptor> #\f #f
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! b-flag #t))))
	     (argdesc2
	      (create <argument-descriptor> "flag" #f
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! b-flag #t))))
	     (argdesc3
	      (create <argument-descriptor> #\o #t
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! str-output-file str-option-arg))))
	     (argdesc4
	      (create <argument-descriptor> "output-file" #t
		    (lambda (((str-option-arg <string>)) <none> nonpure)
		      (set! str-output-file str-option-arg))))
	     (proc-handle-proper-args
	      (lambda (((l-proper-args (:uniform-list <string>)))
		       <none> nonpure)
		(if (= (length l-proper-args) 1)
		    (set! str-input-file
			  (uniform-list-ref l-proper-args 0))
		    (console-display-line "Invalid number of input files."))))
	     (l-arg-descs
	      (list argdesc1 argdesc2 argdesc3 argdesc4))
	     (l-args1 (drop l-args 1)))
	(parse-command-line l-args1 l-arg-descs proc-handle-proper-args))
      (console-display "input file: ")
      (console-display-line str-input-file)
      (console-display "output file: ")
      (console-display-line str-output-file)
      (if b-flag
	  (console-display-line "flag set")
	  (console-display-line "flag unset")))))
