Compare commits

..

No commits in common. "9000c8a46b1a15ecdf173ff941ebd32d0c19db00" and "97e9e41117a328eb4595d22bec98e905c06c4234" have entirely different histories.

7 changed files with 24 additions and 33 deletions

3
.vscode/tasks.json vendored
View file

@ -32,9 +32,6 @@
"command": "clippy", "command": "clippy",
"args": [ "args": [
"--fix", "--fix",
"--lib",
"--bin",
"shrupl",
"--allow-dirty", "--allow-dirty",
"--allow-staged", "--allow-staged",
"--", "--",

View file

@ -41,7 +41,6 @@ impl AppState {
} }
} }
#[must_use]
pub fn try_resume(args: &Cli) -> Option<Self> { pub fn try_resume(args: &Cli) -> Option<Self> {
let inner = CacheFile::try_resume(args) let inner = CacheFile::try_resume(args)
.inspect_err(|e| debug!("could not resume from hash {:?}: {e}", args.get_hash())) .inspect_err(|e| debug!("could not resume from hash {:?}: {e}", args.get_hash()))
@ -139,7 +138,6 @@ impl AppState {
Ok(self.inner.peek_uploading().is_none() && self.inner.queue_empty()) Ok(self.inner.peek_uploading().is_none() && self.inner.queue_empty())
} }
#[must_use]
pub fn rewind_chunk(mut self) -> Option<Self> { pub fn rewind_chunk(mut self) -> Option<Self> {
self.inner = self.inner.rewind_chunk()?; self.inner = self.inner.rewind_chunk()?;

View file

@ -101,26 +101,26 @@ fn parse_sharry_file(data: &str) -> io::Result<Checked> {
} }
impl Cli { impl Cli {
#[must_use] pub fn get_timeout(&self) -> Option<Duration> { pub fn get_timeout(&self) -> Option<Duration> {
(!self.timeout.is_zero()).then_some(self.timeout) (!self.timeout.is_zero()).then_some(self.timeout)
} }
#[must_use] pub fn get_uri(&self) -> Uri { pub fn get_uri(&self) -> Uri {
Uri::new(&self.protocol, &self.url) Uri::new(&self.protocol, &self.url)
} }
#[must_use] pub fn may_retry(&self, tries: u32) -> bool { pub fn may_retry(&self, tries: u32) -> bool {
match self.retry_limit { match self.retry_limit {
0 => true, 0 => true,
limit => tries < limit, limit => tries < limit,
} }
} }
#[must_use] pub fn get_share_request(&self) -> NewShareRequest { pub fn get_share_request(&self) -> NewShareRequest {
NewShareRequest::new(&self.name, self.description.as_ref(), self.max_views) NewShareRequest::new(&self.name, self.description.as_ref(), self.max_views)
} }
#[must_use] pub fn get_level_filter(&self) -> LevelFilter { pub fn get_level_filter(&self) -> LevelFilter {
match self.verbose { match self.verbose {
0 => LevelFilter::Error, 0 => LevelFilter::Error,
1 => LevelFilter::Warn, 1 => LevelFilter::Warn,
@ -134,7 +134,7 @@ impl Cli {
self.files.iter().map(FileTrait::get_name).collect() self.files.iter().map(FileTrait::get_name).collect()
} }
#[must_use] pub fn get_hash(&self) -> String { pub fn get_hash(&self) -> String {
let file_refs = { let file_refs = {
let mut refs: Vec<_> = self.files.iter().collect(); let mut refs: Vec<_> = self.files.iter().collect();
refs.sort_unstable(); refs.sort_unstable();

View file

@ -1,15 +0,0 @@
// TODO fix with documentation
#![allow(clippy::missing_errors_doc)]
mod appstate;
mod cachefile;
mod cli;
mod file;
mod impl_ureq;
pub mod output;
mod sharry;
pub use appstate::AppState;
pub use cli::Cli;
pub use output::{Log, SHRUPL};
pub use sharry::{ClientError, Parameter};

View file

@ -1,3 +1,11 @@
mod appstate;
mod cachefile;
mod cli;
mod file;
mod impl_ureq;
mod output;
mod sharry;
use std::{ use std::{
process, process,
sync::{ sync::{
@ -8,9 +16,12 @@ use std::{
use clap::Parser; use clap::Parser;
use console::{StyledObject, style}; use console::{StyledObject, style};
use log::{debug, info, trace}; use log::{info, trace};
use shrupl::{AppState, Cli, ClientError, Log, Parameter, SHRUPL, output}; use appstate::AppState;
use cli::Cli;
use output::{Log, SHRUPL};
use sharry::{ClientError, Parameter};
fn main() { fn main() {
let check_ctrlc = { let check_ctrlc = {
@ -82,14 +93,14 @@ fn main() {
match p { match p {
// Error 404 (File not found) // Error 404 (File not found)
Parameter::FileID(fid) => { Parameter::FileID(fid) => {
debug!("requeueing file {fid:?}"); trace!("requeueing file {fid:?}");
state.abort_upload(); state.abort_upload();
} }
// Error 404 (Share not found) // Error 404 (Share not found)
Parameter::ShareID(sid) => { Parameter::ShareID(sid) => {
// TODO ask // TODO ask
debug!("rebuilding share {sid:?}"); trace!("rebuilding share {sid:?}");
// rebuild share // rebuild share
let Ok(s) = state.rebuild_share(&args) else { let Ok(s) = state.rebuild_share(&args) else {
@ -106,7 +117,7 @@ fn main() {
}; };
tries += 1; tries += 1;
debug!("State rewound, retrying last chunk (tries: {tries})"); trace!("State rewound, retrying last chunk (tries: {tries})");
state = s; state = s;
} }
} }

View file

@ -10,7 +10,7 @@ type StaticStyled<'t> = LazyLock<StyledObject<&'t str>>;
pub static SHRUPL: StaticStyled = LazyLock::new(|| style("ShrUpl").yellow().bold()); pub static SHRUPL: StaticStyled = LazyLock::new(|| style("ShrUpl").yellow().bold());
#[must_use] pub fn prompt_continue() -> bool { pub fn prompt_continue() -> bool {
let prompt = format!( let prompt = format!(
"This operation has previously been stopped. {}", "This operation has previously been stopped. {}",
style("How to proceed?").cyan() style("How to proceed?").cyan()

View file

@ -149,7 +149,7 @@ impl ClientError {
Self::Unknown(into_string(e)) Self::Unknown(into_string(e))
} }
#[must_use] pub fn is_fatal(&self) -> bool { pub fn is_fatal(&self) -> bool {
match self { match self {
Self::InvalidParameter(p) => p.is_fatal(), Self::InvalidParameter(p) => p.is_fatal(),
Self::Unknown(_) => true, Self::Unknown(_) => true,