run_custom_command: allow using interactive shell on unix (#383)

This commit is contained in:
Utkarsh Gupta
2023-03-17 21:58:58 +05:30
committed by GitHub
parent 250485c826
commit 907465f891
3 changed files with 19 additions and 2 deletions

View File

@@ -44,7 +44,7 @@ Visit the documentation at [topgrade-rs.github.io](https://topgrade-rs.github.io
> **Warning**
> Work in Progress
## Customization
## Configuration
See `config.example.toml` for an example configuration file.
@@ -55,6 +55,14 @@ The configuration should be placed in the following paths depending on the opera
- **Windows** - `%APPDATA%/topgrade.toml`
- **macOS** and **other Unix systems** - `${XDG_CONFIG_HOME:-~/.config}/topgrade.toml`
### Custom Commands
Custom commands can be defined in the config file which can be run before, during, or after the inbuilt commands, as required.
By default, the custom commands are run using a new shell according to the `$SHELL` environment variable on unix (falls back to `sh`) or `pwsh` on windows (falls back to `powershell`).
On unix, if you want to run your command using an interactive shell, for example to source your shell's rc files, you can add `-i` at the start of your custom command.
But note that this requires the command to exit the shell correctly or else the shell will hang indefinitely.
## Remote Execution
You can specify a key called `remote_topgrades` in the configuration file.

View File

@@ -74,6 +74,7 @@
# Custom commands
[commands]
#"Python Environment" = "~/dev/.env/bin/pip install -i https://pypi.python.org/simple -U --upgrade-strategy eager jupyter"
#"Custom command using interactive shell (unix)" = "-i vim_upgrade"
[brew]
#greedy_cask = true

View File

@@ -505,7 +505,15 @@ pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()>
pub fn run_custom_command(name: &str, command: &str, ctx: &ExecutionContext) -> Result<()> {
print_separator(name);
ctx.run_type().execute(shell()).arg("-c").arg(command).status_checked()
let mut exec = ctx.run_type().execute(shell());
#[cfg(unix)]
let command = if let Some(command) = command.strip_prefix("-i ") {
exec.arg("-i");
command
} else {
command
};
exec.arg("-c").arg(command).status_checked()
}
pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {