For instance, if I want to use the dev database during this run and the prod database during that run, it would be nice to have
dev.cfg
DB_HOST=localhost
DB_USER=sally
DB_PW=secret
prod.cfg
DB_HOST=10.11.12.hike
DB_USER=ckaepernick
DB_PW=afro
Then be able to run my chapel program and point to the file
./dotslashables --config=prod.cfg
There was some discussion of this a while ago, but I don't see a ticket for it.
Are DB_HOST, DB_USER, and DB_PW all declared as config const or config var in your program? If yes, they can be set with config files as you request with the option -f.
./dotslashables -f prod.cfg
Oh, that sounds nice. Do you have an example lying around I could follow?
Sure thing:
configs.chpl:
config const a = 1,
b = 2.0,
c = "hello";
writeln((a, b, c));
configs.cfg:
a=2
b=3.14
c="world"
% chpl configs.chpl
% ./configs
(1, 2.0, hello)
% ./configs -f configs.cfg
(2, 3.14, world)
hells^{yes}. Let me try this out. Will be back shortly.
More about the -f flag at the bottom of the setting configuration variables section in the docs.
so, RTFM, Ben? et tu?
I'm not sure what I should do about this:
error: Configuration constants are allowed only at module scope.
and I'm not seeing it in the freakin manual, BEN!!!! I'M LOOKING AT YOU ALBRECHT!
Nota bene: I edited the file to be have the variables be config variables, but they were inside main() so that's what caused the error. Also, in experimenting I learned you can't have spaces in your config file like
FAIREST_IN_THE_LAND = "Betty White"
It will barf on the spaces (but not, presumably, Betty White). It also appears kosher to not have a default value. Maybe others know these things, but I do not...
Okay, this looks like it's working for me. Perhaps we can add some examples to the docs for the slow learners like myself. Thanks, guys!
Okay, this looks like it's working for me.
Great! Should we close this issue then?
Perhaps we can add some examples to the docs for the slow learners like myself.
Could you suggest some examples that would have been useful for you?
You're asking the slow guy to write the manual?
Sure, close the issue unless this is creating a downstream issue I'm unaware of. It would be nice to have an example like
const config svar: string,
ivar: int,
aardvark: [];
proc main() {
// use the configured variables
}
svar="es a var, mang"
ivar=23
aardvard=1,1,2,3,5,6
Along with limitations or cases that would break.
Thanks. That is useful.
Along with limitations or cases that would break.
Is there a specific limitation you ran into that would be worth pointing out?
Is there a specific limitation you ran into that would be worth pointing out?
Not to put words into Brian's mouth, but I assumed he was referring to his note that there couldn't be spaces around the = characters (while letting us think of others that we might be aware of).
There was some discussion of this a while ago, but I don't see a ticket for it.
That was in #7186.
Most helpful comment
Not to put words into Brian's mouth, but I assumed he was referring to his note that there couldn't be spaces around the
=characters (while letting us think of others that we might be aware of).