-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add promptBoolOnce, promptIntOnce, and promptStringOnce init te…
…mplate functions
- Loading branch information
Showing
11 changed files
with
234 additions
and
80 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
assets/chezmoi.io/docs/reference/templates/init-functions/promptBoolOnce.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `promptBoolOnce` *map* *key* *prompt* [*default*] | ||
|
||
`promptBoolOnce` returns *map*.*key* if it exists and is a boolean value, | ||
otherwise it prompts the user for a boolean value with *prompt* and an optional | ||
*default* using `promptBool`. | ||
|
||
!!! example | ||
|
||
``` | ||
{{ $hasGUI := promptBoolOnce . "hasGUI" "Does this machine have a GUI" }} | ||
``` |
11 changes: 11 additions & 0 deletions
11
assets/chezmoi.io/docs/reference/templates/init-functions/promptIntOnce.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `promptIntOnce` *map* *key* *prompt* [*default*] | ||
|
||
`promptIntOnce` returns *map*.*key* if it exists and is an integer value, | ||
otherwise it prompts the user for a integer value with *prompt* and an optional | ||
*default* using `promptInt`. | ||
|
||
!!! example | ||
|
||
``` | ||
{{ $monitors := promptIntOnce . "monitors" "How many monitors does this machine have" }} | ||
``` |
11 changes: 11 additions & 0 deletions
11
assets/chezmoi.io/docs/reference/templates/init-functions/promptStringOnce.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `promptStringOnce` *map* *key* *prompt* [*default*] | ||
|
||
`promptStringOnce` returns *map*.*key* if it exists and is an string value, | ||
otherwise it prompts the user for a string value with *prompt* and an optional | ||
*default* using `promptString`. | ||
|
||
!!! example | ||
|
||
``` | ||
{{ $email := promptStringOnce . "email" "What is your email address" }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# test exit template function | ||
chezmoi execute-template --init '{{ exit 0 }}' | ||
! chezmoi execute-template --init '{{ exit 1 }}' | ||
|
||
# test promptBoolOnce template function with execute-template --init | ||
chezmoi execute-template --init --promptBool bool=true '{{ promptBoolOnce . "bool" "bool" }}' | ||
stdout true | ||
|
||
# test promptIntOnce template function with execute-template --init | ||
chezmoi execute-template --init --promptInt int=1 '{{ promptIntOnce . "int" "int" }}' | ||
stdout 1 | ||
|
||
# test promptStringOnce template function with execute-template --init | ||
chezmoi execute-template --init --promptString string=value '{{ promptStringOnce . "string" "string" }}' | ||
stdout value | ||
|
||
# test writeToStdout template function | ||
chezmoi execute-template --init '{{ writeToStdout "string" }}' | ||
stdout string | ||
|
||
# test prompt*Once functions without existing data | ||
stdin golden/input | ||
chezmoi init | ||
cmp ${CHEZMOICONFIGDIR}/chezmoi.toml golden/chezmoi.toml | ||
|
||
chhome home2/user | ||
|
||
# test prompt*Once functions with existing data | ||
chezmoi init | ||
cmp ${CHEZMOICONFIGDIR}/chezmoi.toml golden/chezmoi.toml | ||
|
||
-- golden/chezmoi.toml -- | ||
[data] | ||
bool = true | ||
int = 1 | ||
string = "value" | ||
-- golden/input -- | ||
true | ||
1 | ||
value | ||
-- home/user/.local/share/chezmoi/.chezmoi.toml.tmpl -- | ||
{{ $bool := promptBoolOnce . "bool" "bool" -}} | ||
{{ $int := promptIntOnce . "int" "int" -}} | ||
{{ $string := promptStringOnce . "string" "string" -}} | ||
|
||
[data] | ||
bool = {{ $bool }} | ||
int = {{ $int }} | ||
string = {{ $string | quote }} | ||
-- home2/user/.config/chezmoi/chezmoi.toml -- | ||
[data] | ||
bool = true | ||
int = 1 | ||
string = "value" |
Oops, something went wrong.