Allow config generation for later use
This commit is contained in:
18
install.sh
18
install.sh
@@ -134,7 +134,6 @@ function generateConfigKeysFromQuestionID() {
|
|||||||
|
|
||||||
function answerQuestionsFromConfigOrAskUser() {
|
function answerQuestionsFromConfigOrAskUser() {
|
||||||
local questionID
|
local questionID
|
||||||
config setappname "de.astzweig.macos.system-setup"
|
|
||||||
for questionID in "${(k)questions[@]}"; do
|
for questionID in "${(k)questions[@]}"; do
|
||||||
local value configkeys=()
|
local value configkeys=()
|
||||||
generateConfigKeysFromQuestionID "${mod}" "${questionID}"
|
generateConfigKeysFromQuestionID "${mod}" "${questionID}"
|
||||||
@@ -149,7 +148,9 @@ function answerQuestionsFromConfigOrAskUser() {
|
|||||||
|
|
||||||
function askNecessaryQuestions() {
|
function askNecessaryQuestions() {
|
||||||
local mod
|
local mod
|
||||||
for mod in "${modulesToInstall[@]}"; do
|
config setappname "de.astzweig.macos.system-setup"
|
||||||
|
[ -n "${config_only}" ] && config setconfigfile "${config_only}"
|
||||||
|
for mod in ${modulesToInstall[@]}; do
|
||||||
local -A questions=()
|
local -A questions=()
|
||||||
populateQuestionsWithModuleRequiredInformation
|
populateQuestionsWithModuleRequiredInformation
|
||||||
answerQuestionsFromConfigOrAskUser
|
answerQuestionsFromConfigOrAskUser
|
||||||
@@ -200,15 +201,19 @@ function main() {
|
|||||||
Usage: $0 [options] [-m PATH]... [<module>...]
|
Usage: $0 [options] [-m PATH]... [<module>...]
|
||||||
|
|
||||||
Install all modules in module search path. If any <module> arg is given,
|
Install all modules in module search path. If any <module> arg is given,
|
||||||
install only modules that either match any given <module> or whose path ends
|
install only modules that either match any given <module> or whose path ends
|
||||||
like any of the given <module>.
|
like any of the given <module>.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-i, --inverse Exclude the given <module> instead.
|
-i, --inverse Exclude the given <module> instead.
|
||||||
-m PATH, --modpath PATH Include PATH in the module search path.
|
-m PATH, --modpath PATH Include PATH in the module search path.
|
||||||
|
-c PATH, --config PATH Read module answers from config file at PATH.
|
||||||
-l, --list List modules that are going to be installed and
|
-l, --list List modules that are going to be installed and
|
||||||
exit without installation. Modules are printed in
|
exit without installation. Modules are printed in
|
||||||
minimal but still distinct paths.
|
minimal but still distinct paths.
|
||||||
|
--config-only PATH Ask module questions, generate config at PATH and
|
||||||
|
exit. Useful for subsequent runs with c option.
|
||||||
|
Any file at PATH will be overwritten.
|
||||||
----
|
----
|
||||||
$0 0.1.0
|
$0 0.1.0
|
||||||
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
||||||
@@ -220,6 +225,7 @@ function main() {
|
|||||||
autoloadZShLib
|
autoloadZShLib
|
||||||
loadModules
|
loadModules
|
||||||
askNecessaryQuestions
|
askNecessaryQuestions
|
||||||
|
[ -z "${config_only}" ] || return 0
|
||||||
installModules
|
installModules
|
||||||
lop debug "Current working dir is: `pwd`"
|
lop debug "Current working dir is: `pwd`"
|
||||||
}
|
}
|
||||||
|
|||||||
30
spec/askNecessaryQuestions_spec.sh
Normal file
30
spec/askNecessaryQuestions_spec.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
Describe 'askNecessaryQuestions'
|
||||||
|
Include ./install.sh
|
||||||
|
|
||||||
|
It 'sets config app name'
|
||||||
|
appname=''
|
||||||
|
config() { [ "$1" = setappname ] && appname="$2" }
|
||||||
|
When call askNecessaryQuestions
|
||||||
|
The variable 'appname' should eq 'de.astzweig.macos.system-setup'
|
||||||
|
End
|
||||||
|
|
||||||
|
It 'sets config file path'
|
||||||
|
configpath=''
|
||||||
|
config() { [ "$1" = setconfigfile ] && configpath="$2" }
|
||||||
|
config_only='/my/file/path'
|
||||||
|
When call askNecessaryQuestions
|
||||||
|
The variable 'configpath' should eq '/my/file/path'
|
||||||
|
End
|
||||||
|
|
||||||
|
It 'writes config to given file'
|
||||||
|
declare -A answers
|
||||||
|
config_only="`mktemp`"
|
||||||
|
modulesToInstall=('mymodule')
|
||||||
|
populateQuestionsWithModuleRequiredInformation() { questions+=('my-question' $'What is my question?\ninfo') }
|
||||||
|
readConfig() { config read mymodule questions my_question }
|
||||||
|
Data 'myanswer'
|
||||||
|
When call askNecessaryQuestions
|
||||||
|
The variable answers should eq 'myanswer'
|
||||||
|
The result of function readConfig should eq 'myanswer'
|
||||||
|
End
|
||||||
|
End
|
||||||
Reference in New Issue
Block a user