-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global config store #267
Global config store #267
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
use anyhow::anyhow; | ||
use clap::{Parser, Subcommand}; | ||
use derive_more::Display; | ||
use gosub_engine::config; | ||
use gosub_engine::config::settings::Setting; | ||
use gosub_engine::config::storage::json_storage::JsonStorageAdapter; | ||
use gosub_engine::config::storage::sqlite_storage::SqliteStorageAdapter; | ||
use gosub_engine::config::{ConfigStore, Store}; | ||
use gosub_engine::config::storage::*; | ||
use gosub_engine::config::StorageAdapter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name "store" was a bit ambiguous. They are actually storage adapters since we already have a config store. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would make sense to reexport the StorageAdapters in use gosub_engine::config::storage::* Then you could also make your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sharktheone Can you guve an example on what you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, doing this in mod json;
mod memory;
mod sqlite;
pub use json::*;
pub use memory::*;
pub use sqlite::*; Then you can do this use gosub_engine::config::storage::* and still use |
||
use std::str::FromStr; | ||
|
||
#[derive(Debug, Parser)] | ||
|
@@ -74,40 +74,40 @@ struct GlobalOpts { | |
fn main() -> anyhow::Result<()> { | ||
let args = Cli::parse(); | ||
|
||
let storage_box: Box<dyn Store> = match args.global_opts.engine { | ||
let storage: Box<dyn StorageAdapter> = match args.global_opts.engine { | ||
Engine::Sqlite => Box::new(SqliteStorageAdapter::try_from(&args.global_opts.path)?), | ||
Engine::Json => Box::new(JsonStorageAdapter::try_from(&args.global_opts.path)?), | ||
}; | ||
|
||
let mut store = ConfigStore::from_storage(storage_box, true)?; | ||
config::config_store_write().set_storage(storage); | ||
|
||
match args.command { | ||
Commands::View { key } => { | ||
if !store.has(&key) { | ||
if !config::config_store().has(&key) { | ||
println!("Key not found"); | ||
return Ok(()); | ||
} | ||
|
||
let info = store.get_info(&key).unwrap(); | ||
let value = store.get(&key); | ||
let info = config::config_store().get_info(&key).unwrap(); | ||
let value = config::config_store().get(&key).unwrap(); | ||
|
||
println!("Key : {}", key); | ||
println!("Current Value : {}", value); | ||
println!("Default Value : {}", info.default); | ||
println!("Description : {}", info.description); | ||
} | ||
Commands::List => { | ||
for key in store.find("*") { | ||
let value = store.get(&key); | ||
for key in config::config_store().find("*") { | ||
let value = config::config_store().get(&key).unwrap(); | ||
println!("{:40}: {}", key, value); | ||
} | ||
} | ||
Commands::Set { key, value } => { | ||
store.set(&key, Setting::from_str(&value).expect("incorrect value")); | ||
config::config_store().set(&key, Setting::from_str(&value).expect("incorrect value")); | ||
} | ||
Commands::Search { key } => { | ||
for key in store.find(&key) { | ||
let value = store.get(&key); | ||
for key in config::config_store().find(&key) { | ||
let value = config::config_store().get(&key).unwrap(); | ||
println!("{:40}: {}", key, value); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a
-
in the filename, I've seen this also in the other files in the bin directory now. Everywhere we have underscores and not dashes in the file names. I guess going for consistency is probably good. I'd generally avoid dashes/spaces and so on in file names, I just use a underscore for it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like dashes in binaries and options :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here — I prefer dashes to underscores in binary executable names. E.g., in Linux, the executable name is
google-chrome
. (For binary executables, even better is a short name with no dashes or underscores.)