If a user passes `--input foo`, print "Searching `foo` for files…", instead of the resolved, absolute path to `foo`, since the former is what the user typed in. This was way harder, and had way more edge cases, than I thought it would be! One takaway, lexical path cleaning is excellent. type: changed fixes: - https://github.com/casey/intermodal/issues/252 - https://github.com/casey/intermodal/issues/332
43 lines
1.0 KiB
Rust
43 lines
1.0 KiB
Rust
use crate::common::*;
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub(crate) enum CreateStep<'a> {
|
|
Searching { input: &'a InputTarget },
|
|
Hashing,
|
|
Writing { output: &'a OutputTarget },
|
|
}
|
|
|
|
impl<'a> Step for CreateStep<'a> {
|
|
fn n(&self) -> usize {
|
|
match self {
|
|
Self::Searching { .. } => 1,
|
|
Self::Hashing => 2,
|
|
Self::Writing { .. } => 3,
|
|
}
|
|
}
|
|
|
|
fn symbol(&self) -> &str {
|
|
match self {
|
|
Self::Searching { .. } => "\u{1F9FF}",
|
|
Self::Hashing => "\u{1F9EE}",
|
|
Self::Writing { .. } => "\u{1F4BE}",
|
|
}
|
|
}
|
|
|
|
fn total() -> usize {
|
|
3
|
|
}
|
|
|
|
fn write_message(&self, write: &mut dyn Write) -> io::Result<()> {
|
|
match self {
|
|
Self::Searching { input } => match input {
|
|
InputTarget::Path(path) => write!(write, "Searching `{}` for files…", path.display()),
|
|
InputTarget::Stdin => write!(write, "Creating single-file torrent from standard input…"),
|
|
},
|
|
|
|
Self::Hashing => write!(write, "Hashing pieces…"),
|
|
Self::Writing { output } => write!(write, "Writing metainfo to {}…", output),
|
|
}
|
|
}
|
|
}
|