Compare commits

..

2 Commits

Author SHA1 Message Date
Thomas Eppers
45f2bb64b0 fixed the rest of the clippy warnings; bumped version to 0.10.0 2021-10-23 13:26:09 +02:00
Thomas Eppers
a718f6f8fb started fixing clippy issues 2021-10-23 13:14:50 +02:00
7 changed files with 30 additions and 27 deletions

2
Cargo.lock generated
View File

@ -673,7 +673,7 @@ dependencies = [
[[package]] [[package]]
name = "reel-moby" name = "reel-moby"
version = "0.9.0" version = "0.10.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"lazy_static", "lazy_static",

View File

@ -1,7 +1,7 @@
[package] [package]
name = "reel-moby" name = "reel-moby"
version = "0.9.0" version = "0.10.0"
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -69,7 +69,7 @@ pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> {
pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> { pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> {
let repo = repo.trim(); let repo = repo.trim();
let split_repo: Vec<&str> = repo.split("/").collect(); let split_repo: Vec<&str> = repo.split('/').collect();
match split_repo.len() { match split_repo.len() {
1 => { 1 => {
let regex = regex::Regex::new(r"[a-z0-9]+").unwrap(); let regex = regex::Regex::new(r"[a-z0-9]+").unwrap();

View File

@ -102,7 +102,6 @@ impl Ui {
Ok(Key::Ctrl('q')) => break 'core, //quit program without saving Ok(Key::Ctrl('q')) => break 'core, //quit program without saving
Ok(Key::Char('\t')) => { Ok(Key::Char('\t')) => {
ui.state.next(); ui.state.next();
()
} }
Ok(Key::Ctrl('s')) => match ui.services.save() { Ok(Key::Ctrl('s')) => match ui.services.save() {
Err(e) => { Err(e) => {
@ -129,7 +128,7 @@ impl Ui {
} }
Ok(tag) => tag, Ok(tag) => tag,
}; };
repo.push_str(":"); repo.push(':');
repo.push_str(&tag); repo.push_str(&tag);
ui.services.change_current_line(repo); ui.services.change_current_line(repo);
} }

View File

@ -107,10 +107,7 @@ impl NoYaml {
ui.repo.confirm(); ui.repo.confirm();
ui.tags = tag_list::TagList::with_repo_name(ui.repo.get()); ui.tags = tag_list::TagList::with_repo_name(ui.repo.get());
} }
State::SelectTag => { State::SelectTag => ui.tags.handle_input(Key::Char('\n')),
ui.tags.get_selected();
()
}
}, },
Ok(Key::Char(key)) => match ui.state { Ok(Key::Char(key)) => match ui.state {
State::EditRepo => { State::EditRepo => {

View File

@ -104,10 +104,7 @@ impl ServiceSwitcher {
/// finds the next image tag in given file /// finds the next image tag in given file
pub fn find_next_match(&mut self) -> bool { pub fn find_next_match(&mut self) -> bool {
let current_line: usize = match self.state.selected() { let current_line: usize = self.state.selected().unwrap_or(0);
None => 0,
Some(i) => i,
};
let mut i = (current_line + 1) % self.list.len(); let mut i = (current_line + 1) % self.list.len();
loop { loop {
@ -131,10 +128,7 @@ impl ServiceSwitcher {
/// finds the previous image tag in given file /// finds the previous image tag in given file
pub fn find_previous_match(&mut self) -> bool { pub fn find_previous_match(&mut self) -> bool {
let current_line: usize = match self.state.selected() { let current_line: usize = self.state.selected().unwrap_or(0);
None => 0,
Some(i) => i,
};
let mut i: usize = if current_line == 0 { let mut i: usize = if current_line == 0 {
self.list.len() - 1 self.list.len() - 1
@ -165,10 +159,10 @@ impl ServiceSwitcher {
/// return the repository from currently selected row /// return the repository from currently selected row
pub fn extract_repo(&self) -> Result<String, Error> { pub fn extract_repo(&self) -> Result<String, Error> {
match self.state.selected() { match self.state.selected() {
None => return Err(Error::NoneSelected), None => Err(Error::NoneSelected),
Some(i) => match repo::match_yaml_image(&self.list[i]) { Some(i) => match repo::match_yaml_image(&self.list[i]) {
Err(_) => return Err(Error::Parsing(String::from("Nothing found"))), Err(_) => Err(Error::Parsing(String::from("Nothing found"))),
Ok((_, repo)) => return Ok(repo.to_string()), Ok((_, repo)) => Ok(repo.to_string()),
}, },
} }
} }

View File

@ -25,6 +25,7 @@ impl fmt::Display for Error {
enum Line { enum Line {
Status(String), Status(String),
Image(tags::Images), Image(tags::Images),
NextPage(String),
} }
impl fmt::Display for Line { impl fmt::Display for Line {
@ -32,6 +33,7 @@ impl fmt::Display for Line {
match self { match self {
Line::Status(s) => write!(f, "{}", s), Line::Status(s) => write!(f, "{}", s),
Line::Image(i) => write!(f, "{}", i), Line::Image(i) => write!(f, "{}", i),
Line::NextPage(s) => write!(f, "{}", s),
} }
} }
} }
@ -68,7 +70,7 @@ impl TagList {
match tags.next_page() { match tags.next_page() {
Err(_) => (), Err(_) => (),
Ok(new_tags) => { Ok(new_tags) => {
lines.push(Line::Status(String::from("load more tags"))); lines.push(Line::NextPage(String::from("load more tags")));
tags = new_tags; tags = new_tags;
} }
}; };
@ -115,24 +117,35 @@ impl TagList {
match key { match key {
Key::Down => self.next(), Key::Down => self.next(),
Key::Up => self.previous(), Key::Up => self.previous(),
Key::Char('\n') => self.select(),
_ => (), _ => (),
} }
} }
/// loads new tags when matching line is selected
fn select(&mut self) {
if let Some(i) = self.state.selected() {
if let Line::NextPage(_) = &self.lines[i] {
self.load_next_page()
}
}
}
pub fn get_selected(&mut self) -> Result<String, Error> { pub fn get_selected(&mut self) -> Result<String, Error> {
match self.state.selected() { match self.state.selected() {
None => Err(Error::NoneSelected), None => Err(Error::NoneSelected),
Some(i) if i == self.lines.len() - 1 => {
self.load_next_page();
Err(Error::NextPageSelected)
}
Some(i) => match &self.lines[i] { Some(i) => match &self.lines[i] {
Line::Status(_) => Err(Error::SelectedStatus), Line::Status(_) => Err(Error::SelectedStatus),
Line::Image(i) => Ok(i.tag_name.clone()), Line::Image(i) => Ok(i.tag_name.clone()),
Line::NextPage(_) => {
self.load_next_page();
Err(Error::NextPageSelected)
}
}, },
} }
} }
/// load new tags from the next page
fn load_next_page(&mut self) { fn load_next_page(&mut self) {
match &self.tags { match &self.tags {
Some(tags) => match tags.next_page() { Some(tags) => match tags.next_page() {
@ -163,7 +176,7 @@ impl TagList {
/// select next tag /// select next tag
fn next(&mut self) { fn next(&mut self) {
match self.state.selected() { match self.state.selected() {
None if self.lines.len() > 0 => self.state.select(Some(0)), None if !self.lines.is_empty() => self.state.select(Some(0)),
None => (), None => (),
Some(i) if i == self.lines.len() - 1 => self.state.select(Some(0)), Some(i) if i == self.lines.len() - 1 => self.state.select(Some(0)),
Some(i) => self.state.select(Some(i + 1)), Some(i) => self.state.select(Some(i + 1)),
@ -173,7 +186,7 @@ impl TagList {
/// select previous tag /// select previous tag
fn previous(&mut self) { fn previous(&mut self) {
match self.state.selected() { match self.state.selected() {
None if self.lines.len() > 0 => self.state.select(Some(self.lines.len())), None if !self.lines.is_empty() => self.state.select(Some(self.lines.len())),
None => (), None => (),
Some(i) if i == 0 => self.state.select(Some(self.lines.len() - 1)), Some(i) if i == 0 => self.state.select(Some(self.lines.len() - 1)),
Some(i) => self.state.select(Some(i - 1)), Some(i) => self.state.select(Some(i - 1)),