All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			See #627
		
			
				
	
	
		
			100 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package app
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"strings"
 | |
| 
 | |
| 	"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/i18n"
 | |
| 	"coopcloud.tech/abra/pkg/log"
 | |
| 	"github.com/charmbracelet/lipgloss"
 | |
| 	"github.com/spf13/cobra"
 | |
| )
 | |
| 
 | |
| // translators: `abra app check` aliases. use a comma separated list of aliases with
 | |
| // no spaces in between
 | |
| var appCheckAliases = i18n.G("chk")
 | |
| 
 | |
| var AppCheckCommand = &cobra.Command{
 | |
| 	// translators: `app check` command
 | |
| 	Use:     i18n.G("check <domain> [flags]"),
 | |
| 	Aliases: strings.Split(appCheckAliases, ","),
 | |
| 	// translators: Short description for `app check` command
 | |
| 	Short: i18n.G("Ensure an app is well configured"),
 | |
| 	Long: i18n.G(`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.`),
 | |
| 	Args: cobra.ExactArgs(1),
 | |
| 	ValidArgsFunction: func(
 | |
| 		cmd *cobra.Command,
 | |
| 		args []string,
 | |
| 		toComplete string) ([]string, cobra.ShellCompDirective) {
 | |
| 		return autocomplete.AppNameComplete()
 | |
| 	},
 | |
| 	Run: func(cmd *cobra.Command, args []string) {
 | |
| 		app := internal.ValidateApp(args)
 | |
| 
 | |
| 		if err := app.Recipe.Ensure(internal.GetEnsureContext()); err != nil {
 | |
| 			log.Fatal(err)
 | |
| 		}
 | |
| 
 | |
| 		table, err := formatter.CreateTable()
 | |
| 		if err != nil {
 | |
| 			log.Fatal(err)
 | |
| 		}
 | |
| 
 | |
| 		table.
 | |
| 			Headers(
 | |
| 				fmt.Sprintf("%s .env.sample", app.Recipe.Name),
 | |
| 				fmt.Sprintf("%s.env", app.Name),
 | |
| 			).
 | |
| 			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...)
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		if err := formatter.PrintTable(table); err != nil {
 | |
| 			log.Fatal(err)
 | |
| 		}
 | |
| 	},
 | |
| }
 | |
| 
 | |
| func init() {
 | |
| 	AppCheckCommand.Flags().BoolVarP(
 | |
| 		&internal.Chaos,
 | |
| 		i18n.G("chaos"),
 | |
| 		i18n.G("C"),
 | |
| 		false,
 | |
| 		i18n.G("ignore uncommitted recipes changes"),
 | |
| 	)
 | |
| }
 |