added a list of common docker-compose file names to open
This commit is contained in:
parent
7203a7309d
commit
e66b75c021
@ -13,11 +13,11 @@ use crate::widget::repo_entry;
|
|||||||
use crate::widget::service_switcher;
|
use crate::widget::service_switcher;
|
||||||
use crate::widget::tag_list;
|
use crate::widget::tag_list;
|
||||||
|
|
||||||
pub struct Ui {
|
pub struct Ui<'a> {
|
||||||
state: State,
|
state: State,
|
||||||
repo: crate::widget::repo_entry::RepoEntry,
|
repo: crate::widget::repo_entry::RepoEntry,
|
||||||
tags: crate::widget::tag_list::TagList,
|
tags: crate::widget::tag_list::TagList,
|
||||||
services: crate::widget::service_switcher::ServiceSwitcher,
|
services: crate::widget::service_switcher::ServiceSwitcher<'a>,
|
||||||
info: crate::widget::info::Info,
|
info: crate::widget::info::Info,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ impl std::iter::Iterator for State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ui {
|
impl Ui<'_> {
|
||||||
pub fn run(repo_id: &str) {
|
pub fn run(repo_id: &str) {
|
||||||
let mut ui = Ui {
|
let mut ui = Ui {
|
||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
|
@ -25,16 +25,20 @@ impl fmt::Display for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServiceSwitcher {
|
pub struct ServiceSwitcher<'a> {
|
||||||
list: Vec<String>,
|
list: Vec<String>,
|
||||||
state: ListState,
|
state: ListState,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
|
opened_file: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServiceSwitcher {
|
impl ServiceSwitcher<'_> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let list = match File::open("docker-compose.yml") {
|
let file_list = vec!["docker-compose.yml", "docker-compose.yaml"];
|
||||||
Err(e) => vec![format!("No docker-compose.yml found: {}", e)],
|
|
||||||
|
for file in file_list {
|
||||||
|
let list = match File::open(file) {
|
||||||
|
Err(_) => continue,
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let buf = BufReader::new(file);
|
let buf = BufReader::new(file);
|
||||||
buf.lines()
|
buf.lines()
|
||||||
@ -43,10 +47,20 @@ impl ServiceSwitcher {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
return Self {
|
||||||
list,
|
list,
|
||||||
state: ListState::default(),
|
state: ListState::default(),
|
||||||
changed: false,
|
changed: false,
|
||||||
|
opened_file: file,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//could not find docker-compose file
|
||||||
|
Self {
|
||||||
|
list: vec![format!("No docker-compose file found")],
|
||||||
|
state: ListState::default(),
|
||||||
|
changed: false,
|
||||||
|
opened_file: "No file",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +72,8 @@ impl ServiceSwitcher {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let title = match &self.changed {
|
let title = match &self.changed {
|
||||||
true => "File: *docker-compose.yml*",
|
true => format!("File: *{}*", self.opened_file),
|
||||||
false => "File: docker-compose.yml",
|
false => format!("File: {}", self.opened_file),
|
||||||
};
|
};
|
||||||
|
|
||||||
let items: Vec<tui::widgets::ListItem> = self
|
let items: Vec<tui::widgets::ListItem> = self
|
||||||
@ -171,8 +185,7 @@ impl ServiceSwitcher {
|
|||||||
|
|
||||||
/// save the currently opened file
|
/// save the currently opened file
|
||||||
pub fn save(&mut self) -> Result<(), std::io::Error> {
|
pub fn save(&mut self) -> Result<(), std::io::Error> {
|
||||||
let name = "docker-compose.yml";
|
let mut file = File::create(self.opened_file)?;
|
||||||
let mut file = File::create(name)?;
|
|
||||||
for line in &self.list {
|
for line in &self.list {
|
||||||
file.write_all(line.as_bytes())?;
|
file.write_all(line.as_bytes())?;
|
||||||
file.write_all("\n".as_bytes())?;
|
file.write_all("\n".as_bytes())?;
|
||||||
|
Loading…
Reference in New Issue
Block a user