mirror of
https://github.com/m-lamonaca/json-to-env.git
synced 2025-04-11 05:16:38 +00:00
remove anyhow
dependency
This commit is contained in:
parent
7086225b40
commit
77dd32e5d0
3 changed files with 7 additions and 15 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -50,12 +50,6 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.0"
|
||||
|
@ -118,7 +112,6 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
|
|||
name = "json2env"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"serde_json",
|
||||
]
|
||||
|
|
|
@ -10,7 +10,6 @@ license = "MIT"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.71"
|
||||
clap = { version = "4.5.0", features = ["derive", "color"] }
|
||||
serde_json = "1.0.97"
|
||||
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,21 +1,21 @@
|
|||
use std::{
|
||||
error::Error,
|
||||
fmt::Display,
|
||||
fs::File,
|
||||
io::{BufRead, BufReader, BufWriter, Read, Write},
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use serde_json::Value;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args = Args::parse();
|
||||
|
||||
let mut reader: Box<dyn BufRead> = match args.input {
|
||||
None => Box::new(std::io::stdin().lock()),
|
||||
Some(ref filename) => {
|
||||
let file = File::open(filename)
|
||||
.with_context(|| format!("Could not open file `{filename}`"))?;
|
||||
.inspect_err(|_| eprintln!("Error: Could not open file `{filename}`"))?;
|
||||
|
||||
Box::new(BufReader::new(file))
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ fn main() -> Result<()> {
|
|||
let input = args.input.unwrap_or("STDIN".to_string());
|
||||
reader
|
||||
.read_to_string(&mut buffer)
|
||||
.with_context(|| format!("Could not read `{input}`"))?;
|
||||
.inspect_err(|_| eprintln!("Error: Could not read `{input}`"))?;
|
||||
|
||||
let json: Value = serde_json::from_str(&buffer)
|
||||
.with_context(|| format!("`{input}` does not contain valid JSON"))?;
|
||||
.inspect_err(|_| eprintln!("Error: `{input}` does not contain valid JSON"))?;
|
||||
|
||||
let mut vars: Vec<EnvVar> = vec![];
|
||||
JsonParser::parse(&mut vars, "", &json, &args.separator);
|
||||
|
@ -44,7 +44,7 @@ fn main() -> Result<()> {
|
|||
None => Box::new(std::io::stdout().lock()),
|
||||
Some(ref filename) => {
|
||||
let file = File::create(filename)
|
||||
.with_context(|| format!("Could not open file `{filename}`"))?;
|
||||
.inspect_err(|_| eprintln!("Error: Could not open file `{filename}`"))?;
|
||||
|
||||
Box::new(BufWriter::new(file))
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ fn main() -> Result<()> {
|
|||
let output = args.output.unwrap_or("STDOUT".to_string());
|
||||
writer
|
||||
.write_all(environ.as_bytes())
|
||||
.with_context(|| format!("Could not write to `{output}`"))?;
|
||||
.inspect_err(|_| eprintln!("Error: Could not write to `{output}`"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue