feat: add version input to abra app new (!400)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Closes coop-cloud/organising#519 Reviewed-on: coop-cloud/abra#400 Reviewed-by: decentral1se <decentral1se@noreply.git.coopcloud.tech> Co-authored-by: p4u1 <p4u1_f4u1@riseup.net> Co-committed-by: p4u1 <p4u1_f4u1@riseup.net>
This commit is contained in:
parent
c5687dfbd7
commit
0a3624c15b
@ -54,9 +54,17 @@ var appNewCommand = cli.Command{
|
||||
internal.OfflineFlag,
|
||||
internal.ChaosFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
ArgsUsage: "[<recipe>]",
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
Before: internal.SubCommandBefore,
|
||||
ArgsUsage: "[<recipe>] [<version>]",
|
||||
BashComplete: func(ctx *cli.Context) {
|
||||
args := ctx.Args()
|
||||
switch len(args) {
|
||||
case 0:
|
||||
autocomplete.RecipeNameComplete(ctx)
|
||||
case 1:
|
||||
autocomplete.RecipeVersionComplete(ctx.Args().Get(0))
|
||||
}
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
|
||||
@ -69,8 +77,14 @@ var appNewCommand = cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := recipePkg.EnsureLatest(recipe.Name); err != nil {
|
||||
logrus.Fatal(err)
|
||||
if c.Args().Get(1) == "" {
|
||||
if err := recipePkg.EnsureLatest(recipe.Name); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if err := recipePkg.EnsureVersion(recipe.Name, c.Args().Get(1)); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,20 @@ func RecipeNameComplete(c *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// RecipeVersionComplete completes versions for the recipe.
|
||||
func RecipeVersionComplete(recipeName string) {
|
||||
catl, err := recipe.ReadRecipeCatalogue(false)
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
|
||||
for _, v := range catl[recipeName].Versions {
|
||||
for v2 := range v {
|
||||
fmt.Println(v2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ServerNameComplete completes server names.
|
||||
func ServerNameComplete(c *cli.Context) {
|
||||
files, err := config.LoadAppFiles("")
|
||||
|
@ -18,9 +18,24 @@ setup(){
|
||||
}
|
||||
|
||||
teardown(){
|
||||
load "$PWD/tests/integration/helpers/common"
|
||||
_rm_app
|
||||
}
|
||||
|
||||
@test "autocomplete" {
|
||||
run $ABRA app new --generate-bash-completion
|
||||
assert_success
|
||||
assert_output --partial "traefik"
|
||||
assert_output --partial "abra-test-recipe"
|
||||
|
||||
# Note: this test needs to be updated when a new version of the test recipe is published.
|
||||
run $ABRA app new abra-test-recipe --generate-bash-completion
|
||||
assert_success
|
||||
assert_output "0.1.0+1.20.0
|
||||
0.1.1+1.20.2
|
||||
0.2.0+1.21.0"
|
||||
}
|
||||
|
||||
@test "create new app" {
|
||||
run $ABRA app new "$TEST_RECIPE" \
|
||||
--no-input \
|
||||
@ -28,10 +43,29 @@ teardown(){
|
||||
--domain "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
||||
assert_output --partial "Your branch is up to date with 'origin/main'."
|
||||
}
|
||||
|
||||
@test "create new app with version" {
|
||||
run $ABRA app new "$TEST_RECIPE" 0.1.1+1.20.2 \
|
||||
--no-input \
|
||||
--server "$TEST_SERVER" \
|
||||
--domain "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" log -1
|
||||
assert_output --partial "453db7121c0a56a7a8f15378f18fe3bf21ccfdef"
|
||||
}
|
||||
|
||||
@test "does not overwrite existing env files" {
|
||||
_new_app
|
||||
run $ABRA app new "$TEST_RECIPE" \
|
||||
--no-input \
|
||||
--server "$TEST_SERVER" \
|
||||
--domain "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
|
||||
run $ABRA app new "$TEST_RECIPE" \
|
||||
--no-input \
|
||||
@ -74,8 +108,7 @@ teardown(){
|
||||
--no-input \
|
||||
--chaos \
|
||||
--server "$TEST_SERVER" \
|
||||
--domain "$TEST_APP_DOMAIN" \
|
||||
--secrets
|
||||
--domain "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
|
||||
@ -88,18 +121,17 @@ teardown(){
|
||||
assert_success
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
||||
assert_output --partial 'behind 3'
|
||||
assert_output --partial "Your branch is behind 'origin/main' by 3 commits, and can be fast-forwarded."
|
||||
|
||||
run $ABRA app new "$TEST_RECIPE" \
|
||||
--no-input \
|
||||
--server "$TEST_SERVER" \
|
||||
--domain "$TEST_APP_DOMAIN" \
|
||||
--secrets
|
||||
--domain "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
||||
refute_output --partial 'behind 3'
|
||||
assert_output --partial "Your branch is up to date with 'origin/main'."
|
||||
|
||||
_reset_recipe
|
||||
}
|
||||
@ -109,7 +141,7 @@ teardown(){
|
||||
assert_success
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
||||
assert_output --partial 'behind 3'
|
||||
assert_output --partial "Your branch is behind 'origin/main' by 3 commits, and can be fast-forwarded."
|
||||
|
||||
# NOTE(d1): need to use --chaos to force same commit
|
||||
run $ABRA app new "$TEST_RECIPE" \
|
||||
@ -117,13 +149,12 @@ teardown(){
|
||||
--offline \
|
||||
--chaos \
|
||||
--server "$TEST_SERVER" \
|
||||
--domain "$TEST_APP_DOMAIN" \
|
||||
--secrets
|
||||
--domain "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
||||
assert_output --partial 'behind 3'
|
||||
assert_output --partial "Your branch is behind 'origin/main' by 3 commits, and can be fast-forwarded."
|
||||
|
||||
_reset_recipe
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user