Compare commits
3 commits
97e9e41117
...
9000c8a46b
| Author | SHA1 | Date | |
|---|---|---|---|
| 9000c8a46b | |||
| d1d7b55585 | |||
| 78fb04403c |
7 changed files with 33 additions and 24 deletions
3
.vscode/tasks.json
vendored
3
.vscode/tasks.json
vendored
|
|
@ -32,6 +32,9 @@
|
||||||
"command": "clippy",
|
"command": "clippy",
|
||||||
"args": [
|
"args": [
|
||||||
"--fix",
|
"--fix",
|
||||||
|
"--lib",
|
||||||
|
"--bin",
|
||||||
|
"shrupl",
|
||||||
"--allow-dirty",
|
"--allow-dirty",
|
||||||
"--allow-staged",
|
"--allow-staged",
|
||||||
"--",
|
"--",
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ 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()))
|
||||||
|
|
@ -138,6 +139,7 @@ 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()?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,3 @@
|
||||||
mod appstate;
|
|
||||||
mod cachefile;
|
|
||||||
mod cli;
|
|
||||||
mod file;
|
|
||||||
mod impl_ureq;
|
|
||||||
mod output;
|
|
||||||
mod sharry;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
process,
|
process,
|
||||||
sync::{
|
sync::{
|
||||||
|
|
@ -16,12 +8,9 @@ use std::{
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use console::{StyledObject, style};
|
use console::{StyledObject, style};
|
||||||
use log::{info, trace};
|
use log::{debug, info, trace};
|
||||||
|
|
||||||
use appstate::AppState;
|
use shrupl::{AppState, Cli, ClientError, Log, Parameter, SHRUPL, output};
|
||||||
use cli::Cli;
|
|
||||||
use output::{Log, SHRUPL};
|
|
||||||
use sharry::{ClientError, Parameter};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let check_ctrlc = {
|
let check_ctrlc = {
|
||||||
|
|
@ -93,14 +82,14 @@ fn main() {
|
||||||
match p {
|
match p {
|
||||||
// Error 404 (File not found)
|
// Error 404 (File not found)
|
||||||
Parameter::FileID(fid) => {
|
Parameter::FileID(fid) => {
|
||||||
trace!("requeueing file {fid:?}");
|
debug!("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
|
||||||
trace!("rebuilding share {sid:?}");
|
debug!("rebuilding share {sid:?}");
|
||||||
|
|
||||||
// rebuild share
|
// rebuild share
|
||||||
let Ok(s) = state.rebuild_share(&args) else {
|
let Ok(s) = state.rebuild_share(&args) else {
|
||||||
|
|
@ -117,7 +106,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
tries += 1;
|
tries += 1;
|
||||||
|
|
||||||
trace!("State rewound, retrying last chunk (tries: {tries})");
|
debug!("State rewound, retrying last chunk (tries: {tries})");
|
||||||
state = s;
|
state = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
12
src/cli.rs
12
src/cli.rs
|
|
@ -101,26 +101,26 @@ fn parse_sharry_file(data: &str) -> io::Result<Checked> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl Cli {
|
||||||
pub fn get_timeout(&self) -> Option<Duration> {
|
#[must_use] pub fn get_timeout(&self) -> Option<Duration> {
|
||||||
(!self.timeout.is_zero()).then_some(self.timeout)
|
(!self.timeout.is_zero()).then_some(self.timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_uri(&self) -> Uri {
|
#[must_use] pub fn get_uri(&self) -> Uri {
|
||||||
Uri::new(&self.protocol, &self.url)
|
Uri::new(&self.protocol, &self.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn may_retry(&self, tries: u32) -> bool {
|
#[must_use] 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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_share_request(&self) -> NewShareRequest {
|
#[must_use] 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_level_filter(&self) -> LevelFilter {
|
#[must_use] 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()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_hash(&self) -> String {
|
#[must_use] 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();
|
||||||
|
|
|
||||||
15
src/lib.rs
Normal file
15
src/lib.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
// 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};
|
||||||
|
|
@ -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());
|
||||||
|
|
||||||
pub fn prompt_continue() -> bool {
|
#[must_use] 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()
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ impl ClientError {
|
||||||
Self::Unknown(into_string(e))
|
Self::Unknown(into_string(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_fatal(&self) -> bool {
|
#[must_use] 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,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue