diff --git a/src/tags.rs b/src/tags.rs index 11d46ee..fde69da 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -20,7 +20,6 @@ pub struct Images { #[derive(Deserialize)] pub struct Tags { - // count: i32, next_page: Option, prev_page: Option, pub results: Vec, @@ -63,6 +62,7 @@ impl Tags { Ok(tags) } + /// checks the repo name and may add a prefix for official images pub fn check_repo(mut name: String) -> Result { //check for right set of characters if name.bytes().any(|c| !c.is_ascii()) { @@ -87,6 +87,7 @@ impl fmt::Display for Images { } } +/// converts a given duration to a readable string fn format_time_nice(time: chrono::Duration) -> String { if time.num_weeks() == 52 { format!("{} Jahr", (time.num_weeks() / 52) as i32) diff --git a/src/ui.rs b/src/ui.rs index 97c0d20..0d042d5 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -179,10 +179,12 @@ impl Ui { terminal.clear().unwrap(); } + /// helper function to show information in TagList fn show_info(&mut self, error: &str) { self.tags = tag_list::TagList::with_status(error); } + /// create a thread for catching input and send them to core loop pub fn spawn_stdin_channel(&self) -> mpsc::Receiver { let (tx, rx) = mpsc::channel::(); diff --git a/src/widget/repo_entry.rs b/src/widget/repo_entry.rs index ed33fa4..844fcde 100644 --- a/src/widget/repo_entry.rs +++ b/src/widget/repo_entry.rs @@ -75,6 +75,7 @@ impl RepoEntry { } } + /// set the widget to unchanged pub fn confirm(&mut self) { self.old_text = self.text.clone(); self.changed = false; diff --git a/src/widget/service_switcher.rs b/src/widget/service_switcher.rs index 390979e..5719a04 100644 --- a/src/widget/service_switcher.rs +++ b/src/widget/service_switcher.rs @@ -88,6 +88,7 @@ impl ServiceSwitcher { (items, &mut self.state) } + /// finds the next image tag in given file pub fn find_next_match(&mut self) -> bool { let current_line: usize = match self.state.selected() { None => 0, @@ -114,6 +115,7 @@ impl ServiceSwitcher { false } + /// finds the previous image tag in given file pub fn find_previous_match(&mut self) -> bool { let current_line: usize = match self.state.selected() { None => 0, @@ -146,7 +148,7 @@ impl ServiceSwitcher { false } - //return the repository from currently selected row + /// return the repository from currently selected row pub fn extract_repo(&self) -> Result { match self.state.selected() { None => return Err(Error::NoneSelected), @@ -161,6 +163,7 @@ impl ServiceSwitcher { } } + /// replace currently selected line with repo and tag pub fn change_current_line(&mut self, repo_with_tag: String) { match self.state.selected() { None => (), @@ -178,6 +181,7 @@ impl ServiceSwitcher { self.changed = true; } + /// save the currently opened file pub fn save(&mut self) -> Result<(), std::io::Error> { let name = "docker-compose.yml"; let mut file = File::create(name)?; diff --git a/src/widget/tag_list.rs b/src/widget/tag_list.rs index 7dc7491..23313ee 100644 --- a/src/widget/tag_list.rs +++ b/src/widget/tag_list.rs @@ -26,23 +26,27 @@ impl fmt::Display for Error { } } } + +/// used for creating a TagList pub enum Type { Status(String), Repo(tags::Tags), } impl TagList { - pub fn new(typ: Type) -> Self { + fn new(typ: Type) -> Self { Self { typ, state: ListState::default(), } } + /// create a TagList with a status message pub fn with_status(status: &str) -> Self { Self::new(Type::Status(String::from(status))) } + /// create a TagList pub fn with_repo(name: String) -> Self { match tags::Tags::new(name) { Err(e) => Self::with_status(&format!("{}", e)), @@ -50,6 +54,7 @@ impl TagList { } } + /// get a list of tag names with info fn print_lines(&self) -> Vec { match &self.typ { Type::Status(line) => vec![line.to_string()], @@ -57,6 +62,7 @@ impl TagList { } } + /// get the list of tag names pub fn get_names(&self) -> Result, Error> { match &self.typ { Type::Status(_) => Err(Error::NoTags), @@ -64,6 +70,7 @@ impl TagList { } } + /// get the selected tag or return an error pub fn get_selected(&self) -> Result { match &self.typ { Type::Status(_) => Err(Error::NoTags), @@ -121,6 +128,7 @@ impl TagList { } } + /// select next tag pub fn next(&mut self) { match self.state.selected() { None if self.print_lines().len() > 0 => self.state.select(Some(0)), @@ -130,6 +138,7 @@ impl TagList { } } + /// select previous tag pub fn previous(&mut self) { match self.state.selected() { None if self.print_lines().len() > 0 => {