Simplify the config file format

This commit is contained in:
Zykino 2023-02-06 00:10:12 +01:00
parent 5956795564
commit f76f6da898
5 changed files with 51 additions and 66 deletions

View File

@ -1,25 +1,18 @@
packages:
- name: Apt
fetch:
exe: sudo
params:
- apt
- update
current_dir: null
env: {}
compile: null
- exe: sudo
params:
- apt
- update
install:
exe: sudo
params:
- apt
- upgrade
- --yes
current_dir: null
env: {}
post_install:
- exe: sudo
params:
- apt
- autoremove
current_dir: null
env: {}

View File

@ -1,14 +1,12 @@
packages:
- name: Flatpack
fetch:
exe: flatpak
params:
- update
- --no-deploy
- --assumeyes
- --noninteractive
current_dir: null
env: {}
- exe: flatpak
params:
- update
- --no-deploy
- --assumeyes
- --noninteractive
install:
exe: flatpak
params:
@ -16,8 +14,6 @@ packages:
- --no-pull
- --assumeyes
- --noninteractive
current_dir: null
env: {}
post-install:
- exe: flatpak
params:
@ -25,5 +21,3 @@ packages:
- --unused
- --assumeyes
- --noninteractive
current_dir: null
env: {}

View File

@ -4,5 +4,3 @@ packages:
exe: pipx
params:
- upgrade-all
current_dir: null
env: {}

View File

@ -4,13 +4,9 @@ packages:
exe: rustup
params:
- update
current_dir: null
env: {}
- name: Cargo
install:
exe: cargo
params:
- install-update
- -a
current_dir: null
env: {}

View File

@ -28,8 +28,8 @@ pub struct System {
#[derive(Debug, Serialize, Deserialize)]
pub struct Package {
pub name: String,
fetch: Option<Cmd>,
compile: Option<Cmd>,
fetch: Option<Vec<Cmd>>,
compile: Option<Vec<Cmd>>,
install: Cmd,
post_install: Option<Vec<Cmd>>,
// deps or rDeps : Tree
@ -39,9 +39,9 @@ pub struct Package {
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Cmd {
exe: String,
params: Vec<String>,
params: Option<Vec<String>>,
current_dir: Option<PathBuf>,
env: HashMap<String, String>,
env: Option<HashMap<String, String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -131,9 +131,9 @@ impl Updater {
compile: None,
install: Cmd {
exe: "rustup".to_owned(),
params: vec!["self".to_owned(), "update".to_owned()],
params: Some(vec!["self".to_owned(), "update".to_owned()]),
current_dir: None,
env: HashMap::new(),
env: None,
},
post_install: None,
});
@ -144,9 +144,9 @@ impl Updater {
compile: None,
install: Cmd {
exe: "cargo".to_owned(),
params: vec!["install-update".to_owned(), "-a".to_owned()],
params: Some(vec!["install-update".to_owned(), "-a".to_owned()]),
current_dir: None,
env: HashMap::new(),
env: None,
},
post_install: None,
});
@ -229,17 +229,19 @@ impl Updater {
impl Package {
pub fn fetch(&self, opt: &Opt) -> Result<()> {
if let Some(fetch) = &self.fetch {
let cmd = fetch.clone().prepare(opt);
let exit_status = cmd
.execute(opt)
.map_err(|err| MyError::new(MyErrorKind::Fetch, err, cmd.clone()))?;
for cmd in fetch {
let cmd = cmd.clone().prepare(opt);
let exit_status = cmd
.execute(opt)
.map_err(|err| MyError::new(MyErrorKind::Fetch, err, cmd.clone()))?;
if !exit_status.success() {
return Err(MyError::new(
MyErrorKind::Fetch,
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
cmd.clone(),
));
if !exit_status.success() {
return Err(MyError::new(
MyErrorKind::Fetch,
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
cmd.clone(),
));
}
}
}
Ok(())
@ -247,17 +249,19 @@ impl Package {
pub fn compile(&self, opt: &Opt) -> Result<()> {
if let Some(compile) = &self.compile {
let cmd = compile.clone().prepare(opt);
let exit_status = cmd
.execute(opt)
.map_err(|err| MyError::new(MyErrorKind::Compile, err, cmd.clone()))?;
for cmd in compile {
let cmd = cmd.clone().prepare(opt);
let exit_status = cmd
.execute(opt)
.map_err(|err| MyError::new(MyErrorKind::Compile, err, cmd.clone()))?;
if !exit_status.success() {
return Err(MyError::new(
MyErrorKind::Compile,
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
cmd.clone(),
));
if !exit_status.success() {
return Err(MyError::new(
MyErrorKind::Compile,
io::Error::new(io::ErrorKind::Other, format!("{}", exit_status)),
cmd.clone(),
));
}
}
}
Ok(())
@ -304,23 +308,23 @@ impl Cmd {
fn new() -> Cmd {
Cmd {
exe: "".into(),
params: vec![],
params: None,
current_dir: None,
env: HashMap::new(),
env: None,
}
}
fn prepare(self, opt: &Opt) -> ActualCmd {
let params = self.params;
let mut env = self.env;
if !env.contains_key("PATH") {
env.insert("PATH".to_owned(), std::env!("PATH").to_owned());
}
// TODO: Im not convinced by helping the user and only escaping the PATH. Either all or none
// This means I need to know how to know which values to pass for (at least) rustup & cargo
let env = match self.env {
Some(env) => env,
None => HashMap::from([("PATH".to_owned(), std::env!("PATH").to_owned())]),
};
ActualCmd {
exe: self.exe,
params,
params: self.params.unwrap_or_default(),
current_dir: self.current_dir,
env,
}