Compare commits
3 Commits
72fd5ec46f
...
246124d4d1
Author | SHA1 | Date | |
---|---|---|---|
|
246124d4d1 | ||
|
eec1836dd3 | ||
|
79577de0f9 |
@ -25,6 +25,9 @@ pub enum Repo {
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
lazy_static::lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\./:]+)").unwrap();
|
||||
@ -37,6 +40,7 @@ pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
|
||||
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> {
|
||||
lazy_static::lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new(r"^([a-z0-9\./[^:]]*):?([a-z0-9._\-]*)").unwrap();
|
||||
@ -59,6 +63,7 @@ pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> {
|
||||
Ok((front, back))
|
||||
}
|
||||
|
||||
/// takes an identifier and changes it to a Repo enum
|
||||
pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> {
|
||||
let repo = repo.trim();
|
||||
let split_repo: Vec<&str> = repo.split('/').collect();
|
||||
|
@ -28,6 +28,16 @@ pub enum State {
|
||||
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 {
|
||||
type Item = Self;
|
||||
|
||||
@ -103,13 +113,14 @@ impl Ui {
|
||||
Ok(Key::Ctrl('q')) => break 'core, //quit program without saving
|
||||
Ok(Key::Char('\t')) => {
|
||||
ui.state.next();
|
||||
ui.info.set_info(&ui.state);
|
||||
}
|
||||
Ok(Key::Ctrl('s')) => match ui.services.save() {
|
||||
Err(e) => {
|
||||
ui.info.set_info(&format!("{}", e));
|
||||
continue;
|
||||
}
|
||||
Ok(_) => ui.info.set_info("Saved compose file"),
|
||||
Ok(_) => ui.info.set_text("Saved compose file"),
|
||||
},
|
||||
Ok(Key::Ctrl('r')) => {
|
||||
ui.repo.confirm();
|
||||
@ -139,7 +150,7 @@ impl Ui {
|
||||
Ok(Key::Char(key)) => match ui.state {
|
||||
State::SelectService => (),
|
||||
State::EditRepo => {
|
||||
ui.info.set_info("Editing Repository");
|
||||
ui.info.set_text("Editing Repository");
|
||||
ui.repo.handle_input(Key::Char(key));
|
||||
}
|
||||
State::SelectTag => (),
|
||||
@ -147,7 +158,7 @@ impl Ui {
|
||||
Ok(Key::Backspace) => match ui.state {
|
||||
State::SelectService => (),
|
||||
State::EditRepo => {
|
||||
ui.info.set_info("Editing Repository");
|
||||
ui.info.set_text("Editing Repository");
|
||||
ui.repo.handle_input(Key::Backspace);
|
||||
}
|
||||
State::SelectTag => (),
|
||||
|
@ -17,6 +17,15 @@ pub enum State {
|
||||
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 {
|
||||
type Item = Self;
|
||||
|
||||
@ -97,6 +106,7 @@ impl NoYaml {
|
||||
Ok(Key::Ctrl('q')) => break 'core,
|
||||
Ok(Key::Char('\t')) => {
|
||||
ui.state.next();
|
||||
ui.info.set_info(&ui.state);
|
||||
}
|
||||
Ok(Key::Ctrl('r')) => {
|
||||
ui.repo.confirm();
|
||||
@ -111,7 +121,7 @@ impl NoYaml {
|
||||
},
|
||||
Ok(Key::Char(key)) => match ui.state {
|
||||
State::EditRepo => {
|
||||
ui.info.set_info("Editing Repository");
|
||||
ui.info.set_text("Editing Repository");
|
||||
ui.repo.handle_input(Key::Char(key));
|
||||
}
|
||||
State::SelectTag => {
|
||||
@ -120,7 +130,7 @@ impl NoYaml {
|
||||
},
|
||||
Ok(Key::Backspace) => match ui.state {
|
||||
State::EditRepo => {
|
||||
ui.info.set_info("Editing Repository");
|
||||
ui.info.set_text("Editing Repository");
|
||||
ui.repo.handle_input(Key::Backspace);
|
||||
}
|
||||
State::SelectTag => (),
|
||||
|
@ -27,7 +27,13 @@ impl Info {
|
||||
.highlight_style(Style::default().bg(Color::Black))
|
||||
}
|
||||
|
||||
pub fn set_info(&mut self, info: &str) {
|
||||
/// set a text to display
|
||||
pub fn set_text(&mut self, info: &str) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ pub struct ServiceSwitcher {
|
||||
|
||||
impl ServiceSwitcher {
|
||||
pub fn new(file: &Option<PathBuf>) -> Option<Self> {
|
||||
//gather possible filenames
|
||||
let mut file_list = vec![
|
||||
PathBuf::from("docker-compose.yml"),
|
||||
PathBuf::from("docker-compose.yaml"),
|
||||
@ -43,6 +44,7 @@ impl ServiceSwitcher {
|
||||
Some(file) => file_list.insert(0, file.clone()),
|
||||
}
|
||||
|
||||
//try filenames
|
||||
for file in file_list {
|
||||
let list = match File::open(&file) {
|
||||
Err(_) => continue,
|
||||
|
Loading…
Reference in New Issue
Block a user