specify in readme how to use a development database

This commit is contained in:
Abraham Toriz 2021-08-11 20:25:21 -05:00
parent 73a0b62c75
commit 1365d6d466
3 changed files with 26 additions and 6 deletions

5
.gitignore vendored
View File

@ -1,4 +1,5 @@
/target
fake_old_config.yml
/*.yml
.env
tiempo.sqlite3
/*.sqlite3
dev_config.toml

View File

@ -194,6 +194,19 @@ Run
to see the options.
### Development database
When developing I prefer not to mess with my own database, so I use this `.env`
file:
export TIMETRAP_CONFIG_FILE=/absolute/path/to/repo/dev_config.toml
PS1="$ "
and when I want to test some commands against such config file I just source it:
source .env
cargo run -- in 'hola'
## Special Thanks
To [timetrap](https://github.com/samg/timetrap) for existing. It is the tool I

View File

@ -68,11 +68,17 @@ impl Config {
pub fn read() -> Result<Config> {
// first try from env variable TIMETRAP_CONFIG_FILE
if let Ok(value) = env::var("TIMETRAP_CONFIG_FILE") {
if value.ends_with(".toml") {
return Self::read_from_toml(value);
return if value.ends_with(".toml") {
let config_path = PathBuf::from(&value);
if config_path.is_file() {
Self::read_from_toml(value)
} else {
Self::create_and_return_config(config_path.parent().unwrap(), &config_path)
}
} else {
return Self::read_from_yaml(value);
}
Self::read_from_yaml(value)
};
}
// Next try from some known directories