Automatically running migration command when enabling/disabling components

pull/974/head
Nils Winkler 2017-05-26 08:43:31 +02:00
parent 0039534517
commit 951fe918c0
2 changed files with 63 additions and 0 deletions

View File

@ -88,6 +88,9 @@ bash-it ()
fi fi
if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then
# Automatically run a migration if required
_bash-it-migrate
for arg in "$@" for arg in "$@"
do do
$func $arg $func $arg
@ -159,6 +162,7 @@ _bash-it-migrate() {
for file_type in "aliases" "plugins" "completion" for file_type in "aliases" "plugins" "completion"
do do
shopt -s nullglob
for f in $BASH_IT/$file_type/enabled/*.bash for f in $BASH_IT/$file_type/enabled/*.bash
do do
typeset ff=$(basename $f) typeset ff=$(basename $f)
@ -169,6 +173,8 @@ _bash-it-migrate() {
typeset single_type=$(echo $ff | awk -F'.' '{print $2}' | sed 's/aliases/alias/g') typeset single_type=$(echo $ff | awk -F'.' '{print $2}' | sed 's/aliases/alias/g')
typeset component_name=$(echo $ff | cut -d'.' -f1) typeset component_name=$(echo $ff | cut -d'.' -f1)
echo "Migrating $single_type $component_name."
disable_func="_disable-$single_type" disable_func="_disable-$single_type"
enable_func="_enable-$single_type" enable_func="_enable-$single_type"
@ -176,6 +182,7 @@ _bash-it-migrate() {
$enable_func $component_name $enable_func $component_name
fi fi
done done
shopt -u nullglob
done done
} }

View File

@ -21,6 +21,12 @@ function local_setup {
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
} }
@test "bash-it: enable the node plugin through the bash-it function" {
run bash-it enable plugin "node"
assert_line "0" 'node enabled with priority 250.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: enable the nvm plugin" { @test "bash-it: enable the nvm plugin" {
run _enable-plugin "nvm" run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.' assert_line "0" 'nvm enabled with priority 225.'
@ -34,6 +40,14 @@ function local_setup {
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ]
} }
@test "bash-it: enable an unknown plugin through the bash-it function" {
run bash-it enable plugin "unknown-foo"
echo "${lines[@]}"
assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.'
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ]
}
@test "bash-it: disable a plugin that is not enabled" { @test "bash-it: disable a plugin that is not enabled" {
run _disable-plugin "sdkman" run _disable-plugin "sdkman"
assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.' assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.'
@ -96,6 +110,48 @@ function local_setup {
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
} }
@test "bash-it: run the migrate command without anything to migrate and nothing enabled" {
run _bash-it-migrate
}
@test "bash-it: run the migrate command without anything to migrate" {
run _enable-plugin "ssh"
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
run _bash-it-migrate
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
}
@test "bash-it: verify that existing components are automatically migrated when something is enabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
run bash-it enable plugin "node"
assert_line "0" 'Migrating plugin nvm.'
assert_line "1" 'nvm disabled.'
assert_line "2" 'nvm enabled with priority 225.'
assert_line "3" 'node enabled with priority 250.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: verify that existing components are automatically migrated when something is disabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
run bash-it disable plugin "node"
assert_line "0" 'Migrating plugin nvm.'
assert_line "1" 'nvm disabled.'
assert_line "2" 'nvm enabled with priority 225.'
assert_line "3" 'node disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: enable all plugins" { @test "bash-it: enable all plugins" {
run _enable-plugin "all" run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs)