Compare commits

..

No commits in common. "246124d4d19ce814f849a943cac4ed630ad87f8d" and "72fd5ec46f1e930140e7801d462129d5cb045217" have entirely different histories.

5 changed files with 6 additions and 40 deletions

View File

@ -25,9 +25,6 @@ pub enum Repo {
} }
/// check if yaml line matches and returns the split of repo string and rest /// check if yaml line matches and returns the split of repo string and rest
/// the first &str is the image tag
/// it will be used to not change the identation
/// the second &str will the the identifier for the image
pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> { pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\./:]+)").unwrap(); static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\./:]+)").unwrap();
@ -40,7 +37,6 @@ pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
Ok((caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str())) Ok((caps.get(1).unwrap().as_str(), caps.get(2).unwrap().as_str()))
} }
/// takes the identifier and splits off the tag it exists
pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> { pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> {
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref REGEX: Regex = Regex::new(r"^([a-z0-9\./[^:]]*):?([a-z0-9._\-]*)").unwrap(); static ref REGEX: Regex = Regex::new(r"^([a-z0-9\./[^:]]*):?([a-z0-9._\-]*)").unwrap();
@ -63,7 +59,6 @@ pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> {
Ok((front, back)) Ok((front, back))
} }
/// takes an identifier and changes it to a Repo enum
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();

View File

@ -28,16 +28,6 @@ pub enum State {
SelectService, SelectService,
} }
impl std::fmt::Display for State {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
State::EditRepo => write!(f, "Edit repository"),
State::SelectTag => write!(f, "Select a tag"),
State::SelectService => write!(f, "Select a image"),
}
}
}
impl std::iter::Iterator for State { impl std::iter::Iterator for State {
type Item = Self; type Item = Self;
@ -113,14 +103,13 @@ 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();
ui.info.set_info(&ui.state);
} }
Ok(Key::Ctrl('s')) => match ui.services.save() { Ok(Key::Ctrl('s')) => match ui.services.save() {
Err(e) => { Err(e) => {
ui.info.set_info(&format!("{}", e)); ui.info.set_info(&format!("{}", e));
continue; continue;
} }
Ok(_) => ui.info.set_text("Saved compose file"), Ok(_) => ui.info.set_info("Saved compose file"),
}, },
Ok(Key::Ctrl('r')) => { Ok(Key::Ctrl('r')) => {
ui.repo.confirm(); ui.repo.confirm();
@ -150,7 +139,7 @@ impl Ui {
Ok(Key::Char(key)) => match ui.state { Ok(Key::Char(key)) => match ui.state {
State::SelectService => (), State::SelectService => (),
State::EditRepo => { State::EditRepo => {
ui.info.set_text("Editing Repository"); ui.info.set_info("Editing Repository");
ui.repo.handle_input(Key::Char(key)); ui.repo.handle_input(Key::Char(key));
} }
State::SelectTag => (), State::SelectTag => (),
@ -158,7 +147,7 @@ impl Ui {
Ok(Key::Backspace) => match ui.state { Ok(Key::Backspace) => match ui.state {
State::SelectService => (), State::SelectService => (),
State::EditRepo => { State::EditRepo => {
ui.info.set_text("Editing Repository"); ui.info.set_info("Editing Repository");
ui.repo.handle_input(Key::Backspace); ui.repo.handle_input(Key::Backspace);
} }
State::SelectTag => (), State::SelectTag => (),

View File

@ -17,15 +17,6 @@ pub enum State {
SelectTag, SelectTag,
} }
impl std::fmt::Display for State {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
State::EditRepo => write!(f, "Edit repository"),
State::SelectTag => write!(f, "Select a tag"),
}
}
}
impl std::iter::Iterator for State { impl std::iter::Iterator for State {
type Item = Self; type Item = Self;
@ -106,7 +97,6 @@ impl NoYaml {
Ok(Key::Ctrl('q')) => break 'core, Ok(Key::Ctrl('q')) => break 'core,
Ok(Key::Char('\t')) => { Ok(Key::Char('\t')) => {
ui.state.next(); ui.state.next();
ui.info.set_info(&ui.state);
} }
Ok(Key::Ctrl('r')) => { Ok(Key::Ctrl('r')) => {
ui.repo.confirm(); ui.repo.confirm();
@ -121,7 +111,7 @@ impl NoYaml {
}, },
Ok(Key::Char(key)) => match ui.state { Ok(Key::Char(key)) => match ui.state {
State::EditRepo => { State::EditRepo => {
ui.info.set_text("Editing Repository"); ui.info.set_info("Editing Repository");
ui.repo.handle_input(Key::Char(key)); ui.repo.handle_input(Key::Char(key));
} }
State::SelectTag => { State::SelectTag => {
@ -130,7 +120,7 @@ impl NoYaml {
}, },
Ok(Key::Backspace) => match ui.state { Ok(Key::Backspace) => match ui.state {
State::EditRepo => { State::EditRepo => {
ui.info.set_text("Editing Repository"); ui.info.set_info("Editing Repository");
ui.repo.handle_input(Key::Backspace); ui.repo.handle_input(Key::Backspace);
} }
State::SelectTag => (), State::SelectTag => (),

View File

@ -27,13 +27,7 @@ impl Info {
.highlight_style(Style::default().bg(Color::Black)) .highlight_style(Style::default().bg(Color::Black))
} }
/// set a text to display pub fn set_info(&mut self, info: &str) {
pub fn set_text(&mut self, info: &str) {
self.info = String::from(info); self.info = String::from(info);
} }
/// print a text to display
pub fn set_info(&mut self, text: &dyn std::fmt::Display) {
self.info = format!("{}", text);
}
} }

View File

@ -34,7 +34,6 @@ pub struct ServiceSwitcher {
impl ServiceSwitcher { impl ServiceSwitcher {
pub fn new(file: &Option<PathBuf>) -> Option<Self> { pub fn new(file: &Option<PathBuf>) -> Option<Self> {
//gather possible filenames
let mut file_list = vec![ let mut file_list = vec![
PathBuf::from("docker-compose.yml"), PathBuf::from("docker-compose.yml"),
PathBuf::from("docker-compose.yaml"), PathBuf::from("docker-compose.yaml"),
@ -44,7 +43,6 @@ impl ServiceSwitcher {
Some(file) => file_list.insert(0, file.clone()), Some(file) => file_list.insert(0, file.clone()),
} }
//try filenames
for file in file_list { for file in file_list {
let list = match File::open(&file) { let list = match File::open(&file) {
Err(_) => continue, Err(_) => continue,