Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upConfiguration and loading from yaml files #61
Conversation
Aceeri
added some commits
May 14, 2016
Aceeri
reviewed
May 16, 2016
| + | ||
| + #[derive(Clone, Debug)] | ||
| + pub struct $root { | ||
| + _meta: ConfigMeta, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
May 16, 2016
Member
Should I move this to be completely invisible/in the background to the user or keep it exposed? It may be useful if we want to do something like writing to the configs as then we would still have the location of file along with the location the Config struct is defined.
Aceeri
May 16, 2016
•
Member
Should I move this to be completely invisible/in the background to the user or keep it exposed? It may be useful if we want to do something like writing to the configs as then we would still have the location of file along with the location the Config struct is defined.
Aceeri
reviewed
May 16, 2016
| + path = path + element; | ||
| + } | ||
| + | ||
| + format!("{}: Failed to parse YAML: {}: expect {}", meta.path.display(), path, meta.ty) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
May 16, 2016
Member
Should probably re-add in a check if the key is a "BadValue", if it then say "Could not find YAML" instead of "Failed to parse YAML".
Aceeri
May 16, 2016
Member
Should probably re-add in a check if the key is a "BadValue", if it then say "Could not find YAML" instead of "Failed to parse YAML".
Aceeri
added some commits
May 17, 2016
lschmierer
reviewed
May 18, 2016
| + | ||
| +#[derive(Clone, Debug)] | ||
| +pub struct ConfigMeta { | ||
| + path: PathBuf, // Where the file is located, "" if not from a file. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
May 20, 2016
Member
Decided to make it default to "config\config.yml" instead as a default directory for amethyst.
Aceeri
May 20, 2016
Member
Decided to make it default to "config\config.yml" instead as a default directory for amethyst.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lschmierer
May 18, 2016
Member
Writing to files? Not sure how necessary this would be.
I think existing Yaml files should be automatically updated to match the layout of the config!{...} defined Configs. So, when the config struct is changed, the developer does not need to take care of the Yaml config files.
I think existing Yaml files should be automatically updated to match the layout of the |
Aceeri
added some commits
May 18, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
May 20, 2016
Member
Looks like this is almost done, couple of rather minor bugs to fix. Currently writing will only write to a separate file if the file already exists in config/, otherwise it will just overwrite the "extern" with the default value.
|
Looks like this is almost done, couple of rather minor bugs to fix. Currently writing will only write to a separate file if the file already exists in config/, otherwise it will just overwrite the "extern" with the default value. |
Aceeri
added some commits
May 21, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Does writing keep comments in the yaml files? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
@lschmierer Not at the moment, hadn't thought of that. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
thiolliere
May 22, 2016
I think that from_file_raw must result in an error if there is there is both display.yml and display/config.yml
thiolliere
commented
May 22, 2016
|
I think that from_file_raw must result in an error if there is there is both display.yml and display/config.yml |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
thiolliere
May 22, 2016
it can also be cool in case display.yml have a key not in its structure definition to warn unexpected key.
thiolliere
commented
May 22, 2016
|
it can also be cool in case display.yml have a key not in its structure definition to warn unexpected key. |
Aceeri
added some commits
May 23, 2016
Aceeri
added some commits
May 31, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
Jun 1, 2016
Member
Alright! I added a warning for unexpected keys in the yaml. from_file() now outputs a warning/error if there are multiple files and defaults instead of loading. And finally, documentation for configuration structures and enums work properly now in the macro, along with custom derives so there is less need for comments inside of the .yml/.yaml files.
So far I've tested on windows and linux and it works great.
|
Alright! I added a warning for unexpected keys in the yaml. So far I've tested on windows and linux and it works great. |
Aceeri
added some commits
Jun 1, 2016
kvark
reviewed
Jun 7, 2016
| +path = "src/config/" | ||
| +version = "0.1.0" | ||
| + | ||
| +[dependencies] |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
added some commits
Jun 7, 2016
kvark
reviewed
Jun 10, 2016
| +use std::path::Path; | ||
| + | ||
| +fn main() { | ||
| + let config = amethyst_config::Config::from_file(Path::new("../../config/config.yml")); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
kvark
Jun 10, 2016
Member
If you use AsRef<Path>, like File::open does, you could avoid Path::new() here.
kvark
Jun 10, 2016
Member
If you use AsRef<Path>, like File::open does, you could avoid Path::new() here.
kvark
reviewed
Jun 10, 2016
| + if index != 0 { | ||
| + tree = tree + "->"; | ||
| + } | ||
| + |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Aceeri
Jun 11, 2016
Member
Just a habit I have, I usually separate things that modify scope. I should probably clean up some of these whitespaces though.
Aceeri
Jun 11, 2016
•
Member
Just a habit I have, I usually separate things that modify scope. I should probably clean up some of these whitespaces though.
kvark
reviewed
Jun 10, 2016
| + } | ||
| + } | ||
| + | ||
| + if array.len() > 10 { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
kvark
reviewed
Jun 10, 2016
| +yaml_array!(7 => 0 1 2 3 4 5 6); | ||
| +yaml_array!(8 => 0 1 2 3 4 5 6 7); | ||
| +yaml_array!(9 => 0 1 2 3 4 5 6 7 8); | ||
| +yaml_array!(10 => 0 1 2 3 4 5 6 7 8 9); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Thanks @Aceeri ! |
Aceeri commentedMay 16, 2016
•
edited
Edited 1 time
-
Aceeri
edited May 20, 2016 (most recent)
Allows using macros to create a structure along with loading a yaml file into that struct.
It isn't entirely finished as I'd like to add a couple more loading types and clean it up a bit, but it would be very helpful if anyone can spot something I missed or give suggestions.
enum Example { Option1, Option2, Option3 }I'm going to be a bit busy until next wednesday, so I probably won't be making any changes until then.