-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
161 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
use url::Url; | ||
|
||
#[derive(Clone, Parser)] | ||
pub struct Args { | ||
pub input: String, | ||
#[arg( | ||
name = "file", | ||
short, | ||
long, | ||
required_unless_present = "url", | ||
conflicts_with = "url", | ||
help = "file to convert" | ||
)] | ||
/// Local file to convert. | ||
/// Mutually exclusive with `--url` | ||
pub input_file: Option<PathBuf>, | ||
|
||
#[arg(name = "url", short, long, help = "url to convert")] | ||
/// Url to convert. | ||
/// This option is slightly broken, and fails to print if a website ever redirects. | ||
/// Mutually exclusive with `--file` | ||
/// | ||
/// Security note: no validation is performed on these urls, they can be used to convert local | ||
/// files, with the `file://` protocol, perform SSRF or use whatever protocols gio happens to | ||
/// support. You are responsible for sanitizing them to prevent these issues | ||
pub input_url: Option<Url>, | ||
|
||
#[arg(default_value = "output.pdf")] | ||
pub output_file: PathBuf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use futures::channel::oneshot; | ||
use std::cell::Cell; | ||
use std::rc::Rc; | ||
|
||
pub struct RuntimeOneshotSender<T>(Rc<Cell<Option<oneshot::Sender<T>>>>); | ||
|
||
impl<T> Clone for RuntimeOneshotSender<T> { | ||
fn clone(&self) -> Self { | ||
Self(Rc::clone(&self.0)) | ||
} | ||
} | ||
|
||
impl<T> RuntimeOneshotSender<T> { | ||
fn new(s: oneshot::Sender<T>) -> Self { | ||
Self(Rc::new(Cell::new(Some(s)))) | ||
} | ||
|
||
pub fn send(&self, value: T) -> Result<(), T> { | ||
if let Some(s) = self.0.take() { | ||
s.send(value) | ||
} else { | ||
tracing::warn!("Runtime oneshot::send called multiple times."); | ||
Err(value) | ||
} | ||
} | ||
} | ||
|
||
pub fn runtime_oneshot<T>() -> (RuntimeOneshotSender<T>, oneshot::Receiver<T>) { | ||
let (s, r) = oneshot::channel(); | ||
let s = RuntimeOneshotSender::new(s); | ||
|
||
(s, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters