mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/scm/command-line.scm: reorganize a little to remove some of
the top-level actions. (gnc:initialize-config-vars): new function -- initialize config vars to defaults, respecting any relevant envt variable overrides. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6367 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
d0191d501e
commit
a15ae2a3fc
@ -15,96 +15,156 @@
|
||||
;; 59 Temple Place - Suite 330 Fax: +1-617-542-2652
|
||||
;; Boston, MA 02111-1307, USA gnu@gnu.org
|
||||
|
||||
(use-modules (srfi srfi-2))
|
||||
|
||||
(define gnc:*command-line-remaining* #f)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;; Configuration variables
|
||||
|
||||
(define gnc:*arg-show-version*
|
||||
(define gnc:*arg-show-version* #f)
|
||||
(define gnc:*arg-show-usage* #f)
|
||||
(define gnc:*arg-show-help* #f)
|
||||
(define gnc:*arg-no-file* #f)
|
||||
(define gnc:*loglevel* #f)
|
||||
|
||||
(define gnc:*config-path* #f)
|
||||
(define gnc:*share-path* #f)
|
||||
(define gnc:*doc-path* #f)
|
||||
|
||||
;; If command line args are present, then those dominate, and take
|
||||
;; effect in order, left-to-right. Otherwise, any envt var setting
|
||||
;; dominates, otherwise, we use the default. To effect this, we first
|
||||
;; set it to the default, then later we process the envt vars, then
|
||||
;; lastly we process the command line.
|
||||
|
||||
(define (gnc:make-path-config-var name default-path-func)
|
||||
(gnc:make-config-var
|
||||
(N_ "Show version.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(define gnc:*arg-show-usage*
|
||||
(gnc:make-config-var
|
||||
(N_ "Generate an argument summary.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(define gnc:*arg-show-help*
|
||||
(gnc:make-config-var
|
||||
(N_ "Generate an argument summary.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(define gnc:*arg-no-file*
|
||||
(gnc:make-config-var
|
||||
(N_ "Don't load any file, including autoloading the last file.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(define gnc:*config-dir*
|
||||
(gnc:make-config-var
|
||||
(N_ "Configuration directory - can be overridden with GNC_CONFIG_DIR environment variable.")
|
||||
(lambda (var value) (if (string? value) (list value) #f))
|
||||
string=?
|
||||
gnc:_install-config-dir_))
|
||||
|
||||
(define gnc:*share-dir*
|
||||
(gnc:make-config-var
|
||||
(N_ "Shared files directory.")
|
||||
(lambda (var value) (if (string? value) (list value) #f))
|
||||
string=?
|
||||
gnc:_install-share-dir_))
|
||||
|
||||
;; Convert the temporary startup value into a config var.
|
||||
(let ((current-value gnc:*debugging?*))
|
||||
(set!
|
||||
gnc:*debugging?*
|
||||
(gnc:make-config-var
|
||||
(N_ "Enable debugging code.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
(gnc:config-var-value-set! gnc:*debugging?* #f current-value))
|
||||
|
||||
(let ((current-value gnc:*debugging?*))
|
||||
(set!
|
||||
gnc:*develmode*
|
||||
(gnc:make-config-var
|
||||
(N_ "Enable developers mode.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
(gnc:config-var-value-set! gnc:*develmode* #f current-value))
|
||||
|
||||
(define gnc:*loglevel*
|
||||
(gnc:make-config-var
|
||||
(N_ "Logging level from 0 (least logging) to 5 (most logging).")
|
||||
(lambda (var value) (if (exact? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(define gnc:*doc-path*
|
||||
|
||||
(gnc:make-config-var
|
||||
(N_ "A list of strings indicating where to look for html and parsed-html files. \
|
||||
Each element must be a string representing a directory or a symbol \
|
||||
where 'default expands to the default path, and 'current expands to \
|
||||
the current value of the path.")
|
||||
name
|
||||
(lambda (var value)
|
||||
(let ((result (gnc:_expand-doc-path_ value)))
|
||||
(let ((result (gnc:expand-path value
|
||||
(gnc:config-var-value-get var)
|
||||
default-path-func)))
|
||||
(if (list? result)
|
||||
(list result)
|
||||
#f)))
|
||||
equal?
|
||||
'(default)))
|
||||
|
||||
(define (gnc:read-from-string str)
|
||||
(call-with-input-string str (lambda (port) (read port))))
|
||||
|
||||
(define (gnc:initialize-config-vars)
|
||||
;; We use a function so we don't do this at file load time.
|
||||
|
||||
(set! gnc:*arg-show-version*
|
||||
(gnc:make-config-var
|
||||
(N_ "Show version.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(set! gnc:*arg-show-usage*
|
||||
(gnc:make-config-var
|
||||
(N_ "Generate an argument summary.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(set! gnc:*arg-show-help*
|
||||
(gnc:make-config-var
|
||||
(N_ "Generate an argument summary.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(set! gnc:*arg-no-file*
|
||||
(gnc:make-config-var
|
||||
(N_ "Don't load any file, including autoloading the last file.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
;; Convert the temporary startup value into a config var.
|
||||
(let ((current-value gnc:*debugging?*))
|
||||
(set!
|
||||
gnc:*debugging?*
|
||||
(gnc:make-config-var
|
||||
(N_ "Enable debugging code.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
(gnc:config-var-value-set! gnc:*debugging?* #f current-value))
|
||||
|
||||
(let ((current-value gnc:*develmode*))
|
||||
(set!
|
||||
gnc:*develmode*
|
||||
(gnc:make-config-var
|
||||
(N_ "Enable developers mode.")
|
||||
(lambda (var value) (if (boolean? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
(gnc:config-var-value-set! gnc:*develmode* #f current-value))
|
||||
|
||||
(set! gnc:*loglevel*
|
||||
(gnc:make-config-var
|
||||
(N_ "Logging level from 0 (least logging) to 5 (most logging).")
|
||||
(lambda (var value) (if (exact? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(set! gnc:*config-path*
|
||||
(gnc:make-path-config-var
|
||||
(N_ "List of directories to search when lookng for config files. \
|
||||
Each element must be a string representing a directory or a symbol \
|
||||
where 'default expands to the default path, and 'current expands to \
|
||||
the current value of the path.")
|
||||
(lambda () gnc:_install-config-path_)))
|
||||
|
||||
(set! gnc:*share-path*
|
||||
(gnc:make-path-config-var
|
||||
(N_ "List of directories to search when lookng for shared data files. \
|
||||
Each element must be a string representing a directory or a symbol \
|
||||
where 'default expands to the default path, and 'current expands to \
|
||||
the current value of the path.")
|
||||
(lambda () gnc:_install-share-path_)))
|
||||
|
||||
|
||||
(set! gnc:*doc-path*
|
||||
(gnc:make-path-config-var
|
||||
(N_ "A list of directories (strings) indicating where to look for html and parsed-html files. \
|
||||
Each element must be a string representing a directory or a symbol \
|
||||
where 'default expands to the default path, and 'current expands to \
|
||||
the current value of the path.")
|
||||
(let ((result (cons
|
||||
(build-path (getenv "HOME") ".gnucash" "html")
|
||||
gnc:_install-doc-path_)))
|
||||
(lambda () result))))
|
||||
|
||||
|
||||
;; Now handle any envt var overrides.
|
||||
|
||||
(and-let* ((envdir (getenv "GNC_CONFIG_PATH"))
|
||||
(data (gnc:read-from-string envdir))
|
||||
((list? data)))
|
||||
(gnc:config-var-value-set! gnc:*config-path* #f (gnc:flatten data)))
|
||||
|
||||
(and-let* ((envdir (getenv "GNC_SHARE_PATH"))
|
||||
(data (gnc:read-from-string envdir))
|
||||
((list? data)))
|
||||
(gnc:config-var-value-set! gnc:*share-path* #f (gnc:flatten data)))
|
||||
|
||||
(and-let* ((envdir (getenv "GNC_DOC_PATH"))
|
||||
(data (gnc:read-from-string envdir))
|
||||
((list? data)))
|
||||
(gnc:config-var-value-set! gnc:*doc-path* #f (gnc:flatten data))))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Argument parsing.
|
||||
|
||||
;; This is a fairly complex initialization during load, but it's OK
|
||||
;; for now since it doesn't depend on running any code.
|
||||
(define gnc:*arg-defs*
|
||||
(list
|
||||
(list "version"
|
||||
@ -156,26 +216,37 @@ the current value of the path.")
|
||||
#f
|
||||
(N_ "Do not load the last file opened"))
|
||||
|
||||
(list "config-dir"
|
||||
(list "config-path"
|
||||
'string
|
||||
(lambda (val)
|
||||
(gnc:config-var-value-set! gnc:*config-dir* #f val))
|
||||
"CONFIGDIR"
|
||||
(N_ "Set configuration directory"))
|
||||
(gnc:debug "parsing --config-path " val)
|
||||
(let ((path-list (gnc:read-from-string val)))
|
||||
(if (list? path-list)
|
||||
(gnc:config-var-value-set! gnc:*config-path* #f path-list)
|
||||
(begin
|
||||
(gnc:error "non-list given for --config-path: " val)
|
||||
(gnc:shutdown 1)))))
|
||||
"CONFIGPATH"
|
||||
(N_ "Set configuration path"))
|
||||
|
||||
(list "share-dir"
|
||||
(list "share-path"
|
||||
'string
|
||||
(lambda (val)
|
||||
(gnc:config-var-value-set! gnc:*share-dir* #f val))
|
||||
"SHAREDIR"
|
||||
(N_ "Set shared directory"))
|
||||
(gnc:debug "parsing --share-path " val)
|
||||
(let ((path-list (gnc:read-from-string val)))
|
||||
(if (list? path-list)
|
||||
(gnc:config-var-value-set! gnc:*share-path* #f path-list)
|
||||
(begin
|
||||
(gnc:error "non-list given for --share-path: " val)
|
||||
(gnc:shutdown 1)))))
|
||||
"SHAREPATH"
|
||||
(N_ "Set shared data file search path"))
|
||||
|
||||
(list "doc-path"
|
||||
'string
|
||||
(lambda (val)
|
||||
(gnc:debug "parsing --doc-path " val)
|
||||
(let ((path-list
|
||||
(call-with-input-string val (lambda (port) (read port)))))
|
||||
(let ((path-list (gnc:read-from-string val)))
|
||||
(if (list? path-list)
|
||||
(gnc:config-var-value-set! gnc:*doc-path* #f path-list)
|
||||
(begin
|
||||
@ -183,7 +254,7 @@ the current value of the path.")
|
||||
(gnc:shutdown 1)))))
|
||||
"DOCPATH"
|
||||
(N_ "Set the search path for documentation files"))
|
||||
|
||||
|
||||
(list "evaluate"
|
||||
'string
|
||||
(lambda (val)
|
||||
@ -347,7 +418,7 @@ the current value of the path.")
|
||||
(set! item (car rest))
|
||||
|
||||
(gnc:debug "handling arg " item)
|
||||
|
||||
|
||||
(if (not (string=? "--"
|
||||
(make-shared-substring item 0
|
||||
(min (string-length item) 2))))
|
||||
|
Loading…
Reference in New Issue
Block a user