Skip to content

Commit

Permalink
deps: toml_edit 0.12.6
Browse files Browse the repository at this point in the history
The `Document::root` field became private in toml_edit 0.7.
We skip ahead to 0.12.6 because that introduced `Document::as_item`,
which greatly simplifies adapting to that change.
  • Loading branch information
gnprice committed Dec 2, 2022
1 parent 8f93d2f commit 9c4fe0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
21 changes: 12 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ nom = "5"
serde = "1.0"
serde_json = "1.0"
structopt = "0.3"
toml_edit = "0.3"
toml_edit = "0.12.6"
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn get(path: PathBuf, query: &str, opts: GetOpts) -> Result<(), Error> {
if opts.output_toml {
print_toml_fragment(&doc, &tpath);
} else {
let item = walk_tpath(&doc.root, &tpath);
let item = walk_tpath(doc.as_item(), &tpath);
// TODO: support shell-friendly output like `jq -r`
println!("{}", serde_json::to_string(&JsonItem(item))?);
}
Expand All @@ -88,7 +88,7 @@ fn get(path: PathBuf, query: &str, opts: GetOpts) -> Result<(), Error> {
fn print_toml_fragment(doc: &Document, tpath: &[TpathSegment]) -> () {
use TpathSegment::{Name, Num};

let mut item = &doc.root;
let mut item = doc.as_item();
let mut breadcrumbs = vec![];
for seg in tpath {
breadcrumbs.push((item, seg));
Expand Down Expand Up @@ -125,16 +125,15 @@ fn print_toml_fragment(doc: &Document, tpath: &[TpathSegment]) -> () {
_ => panic!("UNIMPLEMENTED: --output-toml inside inline data"), // TODO
}
}
let mut doc = Document::new();
doc.root = item;
let doc = Document::from(item.into_table().unwrap());
print!("{}", doc.to_string());
}

fn set(path: PathBuf, query: &str, value_str: &str) -> Result<(), Error> {
let tpath = parse_query_cli(query)?.0;
let mut doc = read_parse(path)?;

let mut item = &mut doc.root;
let mut item = doc.as_item_mut();
let mut already_inline = false;
let mut tpath = &tpath[..];
use TpathSegment::{Name, Num};
Expand Down

0 comments on commit 9c4fe0b

Please sign in to comment.