Skip to content

add functionality to bool2str function #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2015

Conversation

mmckinst
Copy link
Contributor

The bool2str function already exists and converts a boolean true/false to a string true/false. It is not documented in the README.

There are cases when something expects a boolean value to be something other than true/false, such as yes/no, t/f, Yes/No, on/off, etc.

This pull request add an optional two element array that bool2str will accept and convert the boolean true/false to the corresponding value in the array. If no array is given, it converts boolean true/false to a string true/false (which also preserves backwards compatibility).

Examples:

bool2str(true)                   => 'true'
bool2str(true, ['yes', 'no'])    => 'yes'
bool2str(false, ['t', 'f'])      => 'f' 

@DavidS
Copy link
Contributor

DavidS commented Oct 15, 2015

bool2str is already of questionable value, given that it basically implements $val ? { true => 'true', false => 'false', default => fail("need a bool for val, not '$val'") }.

That said, I would still merge this as it has good docs and tests, if you change the array to two separate parameters. That's another two keystrokes saved.

@mmckinst
Copy link
Contributor Author

@DavidS I concur on the usefulness of the old bool2str. Hopefully this will make it more useful because there's been plenty of times where I've done something like $val ? 'On' : 'Off' in a template. But now I can convert values right in a manifest and use augeas or file_line to modify files too.

I've updated and squashed my code so it doesn't use an array any more.

DavidS added a commit that referenced this pull request Oct 16, 2015
add functionality to bool2str function
@DavidS DavidS merged commit 2db7440 into puppetlabs:master Oct 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants