Package: createnv
CreatenvA simple CLI to create.envfiles.MotivationI use.envfile to decouple configuration from application in many projects, and I see that many newcomers might struggle in creating this file.Thus, I created this package to offer a better user interface for creating configuration files in the format of.env.ExampleUsing the sample.env.samplein this repository:You can now experiment by yourself, or try more advanced.env.samplesuch as thetests/.env.sampleor [Bot Followers's.env.sample]InstallCreatenv requiresPython3.7 or newer:$pipinstallcreatenvUsageTo use the default values (reads the sample from.env.sampleand write the result into.env):$createnvOptionsOptionDefaultDescription--target.envFile to write the result--source.env.sampleFile to use as a sample--overwriteand--no-overwrite--no-overwriteWhether to ask before overwriting files--use-defaultor--no-use-default--no-use-defaultWhether to ask for input on fields that have a default value set--chars-for-random-stringAll ASCII letters, numbers and a few extra characters (!@#$%^&*(-_=+))Characters used to create random stringsFormat of sample filesCreatenv reads the sample file and separate lines in blocks, splitting at empty lines. It follows a few rules:The first line is required to be atitleThe second line might be adescriptionor avariableThe remaining lines should bevariablesTitleThe first line of the block should start with a#character, followed by a space. The title value is the remaining text after the#and space.Example# Hell Yeah!In this case, the title isHell yeah!(not# Hell yeah!).Description (optional)If the second line follows the syntax of atitleline, it's text (without the#) is considered adescriptionand is used to give more information to the user about the variables from this block.VariablesThere are three types of variables:RegularEach block might one or more variable lines. The syntax requires aname of variableusing only capital letters, numbers, or underscore, followed by an equal sign.What comes after the equal sign isoptional. This text is considered the default value of this variable.The human description of this variable is alsooptional. You can create one by placing a comment at the end of the line.  That is to say, any text after a sequence oftwo spaces, followed by the#sign and one extra space, is the human description of that variable.ExampleNAME=This is a valid variable line. It has a name (NAME), no default value, and no human description. We can add a default value:NAME=CuducosThis is still a valid variable line. It has a name(NAME), and a default value (Cuducos). Yet, we can add a human description:NAME=Cuducos  # What is your name?Now it's a complete variable with a name (NAME), a default value (Cuducos), and a human description (What is your name?)Random valuesIf you want to have a variable with a random value, you can set its default value to<random>and Createnv will take care of it. Optionally you can specify how long this variable should be with:int.You can use the--chars-for-random-stringoptionto specify which characters to be used in the random value.ExampleSECRET_KEY=<random>
TOKEN=<random:32>The first line will create aSECRET_VALUEwith random characters and random length between 64 and 128 chars.The second line will create aTOKENwith random value and with exactly 32 characters.Auto generatedFinally, you can combine existing variableswithin the same blockto create a new variable (without prompting your user to combine them), the syntax is similar to f-strings in Python..ExampleNAME=  # What is your name?
PERIOD=  # Is it morning, afternoon, or evening?
GREETING=Good {PERIOD}, {NAME}!In this case, Createnv only asks the user forNAMEandPERIOD, and createsGREETINGautomagically.