81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
appPkg "coopcloud.tech/abra/pkg/app"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
"coopcloud.tech/abra/pkg/formatter"
|
|
"coopcloud.tech/abra/pkg/log"
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
var appCheckCommand = cli.Command{
|
|
Name: "check",
|
|
Aliases: []string{"chk"},
|
|
UsageText: "abra app check <domain> [options]",
|
|
Usage: "Ensure an app is well configured",
|
|
Description: `Compare env vars in both the app ".env" and recipe ".env.sample" file.
|
|
|
|
The goal is to ensure that recipe ".env.sample" env vars are defined in your
|
|
app ".env" file. Only env var definitions in the ".env.sample" which are
|
|
uncommented, e.g. "FOO=bar" are checked. If an app ".env" file does not include
|
|
these env vars, then "check" will complain.
|
|
|
|
Recipe maintainers may or may not provide defaults for env vars within their
|
|
recipes regardless of commenting or not (e.g. through the use of
|
|
${FOO:<default>} syntax). "check" does not confirm or deny this for you.`,
|
|
Flags: []cli.Flag{
|
|
internal.ChaosFlag,
|
|
internal.OfflineFlag,
|
|
},
|
|
Before: internal.SubCommandBefore,
|
|
ShellComplete: autocomplete.AppNameComplete,
|
|
HideHelp: true,
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
app := internal.ValidateApp(cmd)
|
|
|
|
if err := app.Recipe.Ensure(internal.Chaos, internal.Offline); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
table, err := formatter.CreateTable()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
table.
|
|
Headers("RECIPE ENV SAMPLE", "APP ENV").
|
|
StyleFunc(func(row, col int) lipgloss.Style {
|
|
switch {
|
|
case col == 1:
|
|
return lipgloss.NewStyle().Padding(0, 1, 0, 1).Align(lipgloss.Center)
|
|
default:
|
|
return lipgloss.NewStyle().Padding(0, 1, 0, 1)
|
|
}
|
|
})
|
|
|
|
envVars, err := appPkg.CheckEnv(app)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
for _, envVar := range envVars {
|
|
if envVar.Present {
|
|
val := []string{envVar.Name, "✅"}
|
|
table.Row(val...)
|
|
} else {
|
|
val := []string{envVar.Name, "❌"}
|
|
table.Row(val...)
|
|
}
|
|
}
|
|
|
|
fmt.Println(table)
|
|
|
|
return nil
|
|
},
|
|
}
|