fix: always panic error
This commit is contained in:
1 parent
8e23f5c335
commit
ccdd62b032
1 file changed
+22
-12
+22
-12
@@ -3,6 +3,7 @@ use html_parser::Node;
|
|||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::process::exit;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
pub mod extract_svgs;
|
pub mod extract_svgs;
|
||||||
@@ -33,6 +34,7 @@ pub struct Translate {
|
|||||||
|
|
||||||
impl Translate {
|
impl Translate {
|
||||||
pub fn translate(self) -> anyhow::Result<()> {
|
pub fn translate(self) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let Translate {
|
let Translate {
|
||||||
component: as_component,
|
component: as_component,
|
||||||
input,
|
input,
|
||||||
@@ -40,21 +42,29 @@ impl Translate {
|
|||||||
source,
|
source,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let contents = input
|
let contents;
|
||||||
|
let temp = input
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
std::fs::read_to_string(&f)
|
std::fs::read_to_string(&f).unwrap_or_else(|e| {
|
||||||
.unwrap_or_else(|e| panic!("Could not read input file: {}", e))
|
// panic!("Could not read input file: {}", e)
|
||||||
})
|
log::error!("Cloud not read input file: {}.", e);
|
||||||
.unwrap_or(source.unwrap_or_else(|| {
|
exit(0);
|
||||||
if atty::is(atty::Stream::Stdin) {
|
})
|
||||||
panic!("No input file, source, or stdin to translate from");
|
});
|
||||||
}
|
if let None = temp {
|
||||||
|
if atty::is(atty::Stream::Stdin) {
|
||||||
|
// panic!("No input file, source, or stdin to translate from");
|
||||||
|
log::error!("No input file, source, or stdin to translate from.");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
std::io::stdin().read_to_string(&mut buffer).unwrap();
|
std::io::stdin().read_to_string(&mut buffer).unwrap();
|
||||||
|
|
||||||
buffer.trim().to_string()
|
contents = buffer.trim().to_string();
|
||||||
}));
|
} else {
|
||||||
|
contents = temp.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// parse the input as html and prepare the output
|
// parse the input as html and prepare the output
|
||||||
let dom = Dom::parse(&contents)?;
|
let dom = Dom::parse(&contents)?;
|
||||||
|
|||||||
Reference in new issue
Block a user