diff --git a/README.md b/README.md index cc5900a9..428e4b59 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,14 @@ git_repos = [ "~/dev/topgrade", ] +[pre_commands] +"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak" + [commands] "Python Environment" = "~/dev/.env/bin/pip install -i https://pypi.python.org/simple -U --upgrade-strategy eager jupyter" ``` +* `git_repos` - A list of custom Git repositories to pull +* `pre_commands` - Commands to execute before starting any action. If any command fails, Topgrade + will not proceed +* `commands` - Custom upgrade steps. If any command fails it will be reported in the summary as all + upgrade steps are reported, but it will not cause Topgrade to stop. diff --git a/src/config.rs b/src/config.rs index 11e12a31..ebc244e0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,9 +5,12 @@ use std::collections::BTreeMap; use std::fs; use toml; +type Commands = BTreeMap; + #[derive(Deserialize, Default)] pub struct Config { - commands: Option>, + pre_commands: Option, + commands: Option, git_repos: Option>, } @@ -30,7 +33,11 @@ impl Config { Ok(result) } - pub fn commands(&self) -> &Option> { + pub fn pre_commands(&self) -> &Option { + &self.pre_commands + } + + pub fn commands(&self) -> &Option { &self.commands } diff --git a/src/main.rs b/src/main.rs index 6e98c8b7..1e02888e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,6 +71,13 @@ fn run() -> Result<(), Error> { None }; + if let Some(commands) = config.pre_commands() { + for (name, command) in commands { + terminal.print_separator(name); + run_custom_command(&command)?; + } + } + if cfg!(target_os = "linux") { terminal.print_separator("System update"); match linux::Distribution::detect() {