It looks like you have a slightly different scenario in mind. You can see an example of what I said for example here. I.e. it is assumed, that the user should do the following
- Clone your application
- Copy
secrets_template.jl
to secrets.jl
- Edit file
secrets.jl
by hand.
Of course, it means, that the user is advanced enough, to understand what is .gitignore
, how relative paths are working and can without errors edit julia files. If it is a problem, then I would recommend to use environment variables, it is much easier to explain and it is less error prone.
You can try to find middle ground, by using .env
file, so less advanced users can just setup environment variables on os level, and more advanced users can write all values in .env
file and get a more flexible approach. To avoid issues with file sourcing, you can add something like this to the beginning of your application
function load_dotenv(filename = ".env")
isfile(filename) || return
for line in eachline(filename)
var, val = strip.(split(line, "="))
ENV[var] = val
end
end
load_dotenv()
This way .env
will override any environment variables and will do nothing if the file does not exist. As a side note, it could be good to revive DotEnv.jl which was written specifically for this purposes.
Of course, you still can simplify users life by creating something like gen_dotenv.jl
with the content
function gen_dotenv()
print("User: ")
user = readline()
pass = read(Base.getpass("Password"), String)
open(".env", "w") do io
println(io, "USER = ", user)
print(io, "PASSWORD = ", pass)
end
end
gen_dotenv()
and explain to a user, that he should run this script at the root of the application.