Move step running into enum for dynamic ordering (#1188)

Co-authored-by: Stuart Reilly <sreilly@scottlogic.com>
This commit is contained in:
Stuart Reilly
2025-07-16 10:16:27 +01:00
committed by GitHub
parent 6719ff93d8
commit 75ac6808a1
22 changed files with 951 additions and 530 deletions

View File

@@ -16,7 +16,7 @@ In `topgrade`'s term, package manager is called `step`.
To add a new `step` to `topgrade`:
1. Add a new variant to
[`enum Step`](https://github.com/topgrade-rs/topgrade/blob/cb7adc8ced8a77addf2cb051d18bba9f202ab866/src/config.rs#L100)
[`enum Step`](https://github.com/topgrade-rs/topgrade/blob/main/src/step.rs)
```rust
pub enum Step {
@@ -32,9 +32,9 @@ To add a new `step` to `topgrade`:
2. Implement the update function
You need to find the appropriate location where this update function goes, it should be
a file under [`src/steps`](https://github.com/topgrade-rs/topgrade/tree/master/src/steps),
a file under [`src/steps`](https://github.com/topgrade-rs/topgrade/tree/main/src/steps),
the file names are self-explanatory, for example, `step`s related to `zsh` are
placed in [`steps/zsh.rs`](https://github.com/topgrade-rs/topgrade/blob/master/src/steps/zsh.rs).
placed in [`steps/zsh.rs`](https://github.com/topgrade-rs/topgrade/blob/main/src/steps/zsh.rs).
Then you implement the update function, and put it in the file where it belongs.
@@ -61,17 +61,17 @@ To add a new `step` to `topgrade`:
[here](https://github.com/topgrade-rs/topgrade/blob/7e48c5dedcfd5d0124bb9f39079a03e27ed23886/src/main.rs#L201-L219)).
Update function would usually do 3 things:
1. Check if the step is installed
2. Output the Separator
3. Invoke the step
1. Check if the step is installed
2. Output the Separator
3. Invoke the step
Still, this is sufficient for most tools, but you may need some extra stuff
with complicated `step`.
3. Finally, invoke that update function in `main.rs`
3. Add a match arm to `Step::run()`
```rust
runner.execute(Step::Xxx, "xxx", || ItsModule::run_xxx(&ctx))?;
Xxx => runner.execute(*self, "xxx", || ItsModule::run_xxx(ctx))?
```
We use [conditional compilation](https://doc.rust-lang.org/reference/conditional-compilation.html)
@@ -86,19 +86,25 @@ To add a new `step` to `topgrade`:
}
```
4. Finally, add the step to `default_steps()` in `step.rs`
```rust
steps.push(Xxx)
```
Try to keep the conditional compilation the same as in the above step 3.
Congrats, you just added a new `step` :)
## Modification to the configuration entries
If your PR has the configuration options
(in [`src/config.rs`](https://github.com/topgrade-rs/topgrade/blob/master/src/config.rs))
(in [`src/config.rs`](https://github.com/topgrade-rs/topgrade/blob/main/src/config.rs))
modified:
1. Adding new options
2. Changing the existing options
Be sure to apply your changes to
[`config.example.toml`](https://github.com/topgrade-rs/topgrade/blob/master/config.example.toml),
[`config.example.toml`](https://github.com/topgrade-rs/topgrade/blob/main/config.example.toml),
and have some basic documentations guiding user how to use these options.
## Breaking changes
@@ -138,7 +144,7 @@ without arguments (e.g., "hello world"), we can simply translate them according
arguments, e.g., "hello <NAME>", please follow this convention:
```yml
"hello {name}": # key
"hello {name}": # key
en: "hello %{name}" # translation
```