fulldecent / swift5-module-template

An opinionated starting point for awesome, reusable Swift 5 modules
MIT License
450 stars 56 forks source link

Pre-define answers via environment variables #28

Closed claui closed 7 years ago

claui commented 7 years ago

If ran regularly, it might be useful for the ./configure program to accept pre-defined answers to the interactive questions.

To that end, this PR adds support for eight environment variables.

Summary

This PR adds support for the following environment variables:

Template variable Ways to pre-define Example
__ORGANIZATION NAME__ To pre-define an answer, define an environment variable named SMT_ORGANIZATION_NAME1. export SMT_ORGANIZATION_NAME='Awesome Org'
com.AN.ORGANIZATION.IDENTIFIER To pre-define an answer, define an environment variable named SMT_COM_AN_ORGANIZATION_IDENTIFIER. export SMT_COM_AN_ORGANIZATION_IDENTIFIER='com.awesome'
__AUTHOR NAME__ To pre-define an answer, define an environment variable named SMT_AUTHOR_NAME. export SMT_AUTHOR_NAME='Mr McAwesome'
__TODAYS_DATE__ To pre-define an answer, define an environment variable named SMT_TODAYS_DATE.

Alternatively, you can use SMT_DATE_FORMAT_STRING to pre-define a date format. The program will still ask you for today’s date; however, it will use the format provided in this variable.
export SMT_TODAYS_DATE='her birthday'

export SMT_DATE_FORMAT_STRING='%F'
__TODAYS_YEAR__ To pre-define an answer, define an environment variable named SMT_TODAYS_YEAR. export SMT_TODAYS_YEAR='2077'
__GITHUB_USERNAME__ To pre-define an answer, define an environment variable named SMT_GITHUB_USERNAME. export SMT_GITHUB_USERNAME='awesome_octocat'
__PROJECT_NAME__ As an alternative to passing your project name as a single command-line argument to ./configure, this PR also supports the SMT_PROJECT_NAME environment variable. The command-line-argument should remain the preferred way; I only added this variable to maintain consistency. ./configure MyFantasticProject remains the preferred way to do this.

[1] SMT is just a short-hand for Swift module template.

If any of the above environment variables is defined, the ./configure program will use its value in lieu of asking interactively; if the variable is undefined, the program will prompt as usual. If neither is successful, it will fall back to the built-in default values.

Specifying a default format string

The SMT_DATE_FORMAT_STRING variable is a special case; if it is defined, the ./configure program will still ask for today’s date interactively; however, it will use the provided date format.

Documentation

This PR adds a new section Setting up pre-defined answers to README.md.

fulldecent commented 7 years ago

Yes, makes lots of sense for scripting, thank you!