Crates.io | nest-cli |
lib.rs | nest-cli |
version | 0.3.0 |
source | src |
created_at | 2019-04-27 12:48:07.313776 |
updated_at | 2019-05-06 10:10:37.630073 |
description | Use your filesystem as a nested data store |
homepage | |
repository | https://github.com/ahdinosaur/nest |
max_upload_size | |
id | 130493 |
size | 5,396 |
nest
use nest::{Error, Store, Value};
use serde_json::json;
use std::convert::TryInto;
fn main() -> Result<(), Error> {
// what is the root path to your data store?
let root = "./example-data";
// describe how your data store will map to the filesystem
let schema = json!({
// refers to a directory: ./example-data/hello/
"hello": {
// refers to a file: ./example-data/hello/world.json
"world": "json"
}
})
.try_into()?;
let store = Store::new(root, schema);
// get `nest` key from `./example-data/hello/world.json` file
let value = store.get(&["hello", "world", "nest"])?;
println!("value: {:?} == 🐣", value);
// set `nest` key in `./example-data/hello/world.json` file
let next_value = &Value::String("🐥".into());
store.set(&["hello", "world", "nest"], next_value)?;
// get a sub-store for data within `./example-data/hello/world.json
let sub = store.sub(&["hello", "world"])?;
let value = sub.get(&["nest"])?;
println!("value: {:?} == 🐥", value);
// try to get a value that doesn't map to the schema
if let Err(err) = store.get(&["invalid", "path"]) {
println!("err: {}", err);
};
Ok(())
}
nest-cli
cargo install nest-cli
Given example-data
:
tree -a example-data
# example-data
# ├── hello
# │ └── world.json
# └── .nest.json
#
# 1 directory, 2 files
cat example-data/.nest.json
# {
# "hello": {
# "world": "json"
# }
# }
cat example-data/hello/world.json
# {
# "nest": "🐣"
# }
cd example-data
nest get 'hello/world'
# {
# "nest": "🐣"
# }
nest set 'hello/world/nest' '"🐥"'
nest get 'hello'
# {
# "world": {
# "nest": "🐥"
# }
# }
Use your filesystem as a nested data store!
USAGE:
nest [FLAGS] [OPTIONS] <SUBCOMMAND>
FLAGS:
-h, --help
Prints help information
-P, --pretty
Enable pretty printing
-V, --version
Prints version information
-v, --verbosity
Pass many times for more log output
By default, it'll only report errors. Passing `-v` one time also prints warnings, `-vv` enables info
logging, `-vvv` debug, and `-vvvv` trace.
OPTIONS:
--root <root>
SUBCOMMANDS:
get Get value from Nest.
help Prints this message or the help of the given subcommand(s)
set Set value in Nest.
The Nest project adheres to the Contributor Covenant Code of Conduct. This describes the minimum behavior expected from all contributors.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license and Developer Certificate of Origin, shall be dual licensed as above, without any additional terms or conditions.