minor refactoring

- `use crate::` where appropriate
- cleanup CLI parsing
- `Uri::with_protocol` -> `Uri::new`
This commit is contained in:
Jörn-Michael Miehe 2025-06-18 13:04:04 +00:00
parent 6ca3e6c9dd
commit de07d556a2
5 changed files with 11 additions and 8 deletions

View file

@ -55,6 +55,7 @@
- client error rework - client error rework
- current variants are too "low level" - current variants are too "low level"
- use variants like `InvalidEndpoint`, `InvalidAlias` etc. - use variants like `InvalidEndpoint`, `InvalidAlias` etc.
- `Uploading::abort() -> Checked`
- hashing - hashing
- store file hashes with all `file::*` variants - store file hashes with all `file::*` variants

View file

@ -8,7 +8,7 @@ use console::style;
use indicatif::{ProgressBar, ProgressStyle}; use indicatif::{ProgressBar, ProgressStyle};
use log::{debug, warn}; use log::{debug, warn};
use super::{ use crate::{
cachefile::CacheFile, cachefile::CacheFile,
cli::Cli, cli::Cli,
file::{self, Chunk, FileTrait}, file::{self, Chunk, FileTrait},

View file

@ -8,7 +8,7 @@ use std::{
use log::trace; use log::trace;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::{ use crate::{
cli::Cli, cli::Cli,
file::{self, FileTrait}, file::{self, FileTrait},
sharry::{self, Client, Uri}, sharry::{self, Client, Uri},

View file

@ -1,6 +1,8 @@
use std::{ use std::{
convert::Infallible,
fmt, fmt,
hash::{DefaultHasher, Hash, Hasher}, hash::{DefaultHasher, Hash, Hasher},
io,
time::Duration, time::Duration,
}; };
@ -10,7 +12,7 @@ use clap::{
value_parser, value_parser,
}; };
use super::{ use crate::{
file::Checked, file::Checked,
sharry::{NewShareRequest, Uri}, sharry::{NewShareRequest, Uri},
}; };
@ -79,12 +81,12 @@ impl fmt::Debug for Cli {
} }
} }
fn parse_seconds(data: &str) -> Result<Duration, String> { fn parse_seconds(data: &str) -> Result<Duration, Infallible> {
data.parse().or(Ok(0)).map(Duration::from_secs) data.parse().or(Ok(0)).map(Duration::from_secs)
} }
fn parse_sharry_file(data: &str) -> Result<Checked, String> { fn parse_sharry_file(data: &str) -> io::Result<Checked> {
Checked::new(data).map_err(|e| e.to_string()) Checked::new(data)
} }
impl Cli { impl Cli {
@ -93,7 +95,7 @@ impl Cli {
} }
pub fn get_uri(&self) -> Uri { pub fn get_uri(&self) -> Uri {
Uri::with_protocol(&self.protocol, &self.url) Uri::new(&self.protocol, &self.url)
} }
pub fn get_share_request(&self) -> NewShareRequest { pub fn get_share_request(&self) -> NewShareRequest {

View file

@ -10,7 +10,7 @@ pub struct Uri {
} }
impl Uri { impl Uri {
pub fn with_protocol(protocol: impl Into<String>, base_url: impl Into<String>) -> Self { pub fn new(protocol: impl Into<String>, base_url: impl Into<String>) -> Self {
Self { Self {
protocol: protocol.into(), protocol: protocol.into(),
base_url: base_url.into(), base_url: base_url.into(),