implemented custom docker-compose file
This commit is contained in:
parent
c8b2bf991c
commit
14658e9253
@ -14,11 +14,11 @@ use crate::widget::service_switcher;
|
|||||||
use crate::widget::tag_list;
|
use crate::widget::tag_list;
|
||||||
use crate::Opt;
|
use crate::Opt;
|
||||||
|
|
||||||
pub struct Ui<'a> {
|
pub struct Ui {
|
||||||
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<'a>,
|
services: crate::widget::service_switcher::ServiceSwitcher,
|
||||||
info: crate::widget::info::Info,
|
info: crate::widget::info::Info,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ impl std::iter::Iterator for State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ui<'_> {
|
impl Ui {
|
||||||
pub fn run(opt: &Opt) {
|
pub fn run(opt: &Opt) {
|
||||||
let (repo_id, load_repo) = match &opt.repo {
|
let (repo_id, load_repo) = match &opt.repo {
|
||||||
None => (
|
None => (
|
||||||
@ -56,7 +56,7 @@ impl Ui<'_> {
|
|||||||
state: State::SelectService,
|
state: State::SelectService,
|
||||||
repo: repo_entry::RepoEntry::new(repo_id),
|
repo: repo_entry::RepoEntry::new(repo_id),
|
||||||
tags: tag_list::TagList::with_status("Tags are empty"),
|
tags: tag_list::TagList::with_status("Tags are empty"),
|
||||||
services: service_switcher::ServiceSwitcher::new(),
|
services: service_switcher::ServiceSwitcher::new(&opt.config),
|
||||||
info: info::Info::new("Select image of edit Repository"),
|
info: info::Info::new("Select image of edit Repository"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ use std::fs::File;
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use tui::style::{Color, Style};
|
use tui::style::{Color, Style};
|
||||||
use tui::widgets::{Block, Borders, List, ListState};
|
use tui::widgets::{Block, Borders, List, ListState};
|
||||||
@ -25,19 +26,26 @@ impl fmt::Display for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServiceSwitcher<'a> {
|
pub struct ServiceSwitcher {
|
||||||
list: Vec<String>,
|
list: Vec<String>,
|
||||||
state: ListState,
|
state: ListState,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
opened_file: &'a str,
|
opened_file: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServiceSwitcher<'_> {
|
impl ServiceSwitcher {
|
||||||
pub fn new() -> Self {
|
pub fn new(file: &Option<PathBuf>) -> Self {
|
||||||
let file_list = vec!["docker-compose.yml", "docker-compose.yaml"];
|
let mut file_list = vec![
|
||||||
|
PathBuf::from("docker-compose.yml"),
|
||||||
|
PathBuf::from("docker-compose.yaml"),
|
||||||
|
];
|
||||||
|
match &file {
|
||||||
|
None => (),
|
||||||
|
Some(file) => file_list.insert(0, file.clone()),
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let buf = BufReader::new(file);
|
let buf = BufReader::new(file);
|
||||||
@ -60,7 +68,7 @@ impl ServiceSwitcher<'_> {
|
|||||||
list: vec![format!("No docker-compose file found")],
|
list: vec![format!("No docker-compose file found")],
|
||||||
state: ListState::default(),
|
state: ListState::default(),
|
||||||
changed: false,
|
changed: false,
|
||||||
opened_file: "No file",
|
opened_file: PathBuf::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +80,8 @@ impl ServiceSwitcher<'_> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let title = match &self.changed {
|
let title = match &self.changed {
|
||||||
true => format!("File: *{}*", self.opened_file),
|
true => format!("File: *{}*", &self.opened_file.display()),
|
||||||
false => format!("File: {}", self.opened_file),
|
false => format!("File: {}", &self.opened_file.display()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let items: Vec<tui::widgets::ListItem> = self
|
let items: Vec<tui::widgets::ListItem> = self
|
||||||
@ -185,7 +193,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 mut file = File::create(self.opened_file)?;
|
let mut file = File::create(&self.opened_file)?;
|
||||||
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