run_custom_command: allow using interactive shell on unix (#383)
This commit is contained in:
10
README.md
10
README.md
@@ -44,7 +44,7 @@ Visit the documentation at [topgrade-rs.github.io](https://topgrade-rs.github.io
|
|||||||
> **Warning**
|
> **Warning**
|
||||||
> Work in Progress
|
> Work in Progress
|
||||||
|
|
||||||
## Customization
|
## Configuration
|
||||||
|
|
||||||
See `config.example.toml` for an example configuration file.
|
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`
|
- **Windows** - `%APPDATA%/topgrade.toml`
|
||||||
- **macOS** and **other Unix systems** - `${XDG_CONFIG_HOME:-~/.config}/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
|
## Remote Execution
|
||||||
|
|
||||||
You can specify a key called `remote_topgrades` in the configuration file.
|
You can specify a key called `remote_topgrades` in the configuration file.
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
# Custom commands
|
# Custom commands
|
||||||
[commands]
|
[commands]
|
||||||
#"Python Environment" = "~/dev/.env/bin/pip install -i https://pypi.python.org/simple -U --upgrade-strategy eager jupyter"
|
#"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]
|
[brew]
|
||||||
#greedy_cask = true
|
#greedy_cask = true
|
||||||
|
|||||||
@@ -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<()> {
|
pub fn run_custom_command(name: &str, command: &str, ctx: &ExecutionContext) -> Result<()> {
|
||||||
print_separator(name);
|
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<()> {
|
pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user