Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var EditCmd = &cobra.Command{ Use: "edit", Short: "✏️ Edit '.env' file using built-in editor", RunE: func(cmd *cobra.Command, _ []string) error { cwd, err := os.Getwd() if err != nil { return err } dotenvFile := filepath.Join(cwd, ".env") dotenvFileLines, contents := readDotenvFile(dotenvFile) variables := envbuilder.ParseVariablesOnly(dotenvFileLines) screen := editorScreen if repo.IsInRepo() { if handleExtraEnvVars(variables) { screen = wizardScreen } } m := Model{ initialScreen: screen, DotenvFile: dotenvFile, variables: variables, contents: contents, SuccessCmd: tea.Quit, } _, err = tui.Run(m, tea.WithAltScreen(), tea.WithContext(cmd.Context())) return err }, }
View Source
var SetupCmd = &cobra.Command{ Use: "setup", Short: "🧙 Environment configuration wizard", Long: `Launch the interactive environment configuration wizard. This wizard will help you: 1️⃣ Review required environment variables 2️⃣ Configure API keys and credentials 3️⃣ Set up database connections (if needed) 4️⃣ Validate your configuration 💡 Perfect for first-time setup or when adding new integrations.`, PreRunE: auth.EnsureAuthenticatedE, RunE: func(cmd *cobra.Command, _ []string) error { repositoryRoot, err := ensureInRepo() if err != nil { return err } dotenvFile := filepath.Join(repositoryRoot, ".env") flagIfNeededSet, _ := cmd.Flags().GetBool("if-needed") if flagIfNeededSet { shouldSkipSetup, err := shouldSkipSetup(repositoryRoot, dotenvFile) if err != nil { return err } if shouldSkipSetup { fmt.Println("Configuration already exists, skipping setup.") return nil } } dotenvFileLines, _ := readDotenvFile(dotenvFile) variables, contents := envbuilder.VariablesFromLines(dotenvFileLines) showAllPrompts, _ := cmd.Flags().GetBool("all") needsPulumi, pulumiLoggedIn, needsPassphrase := CheckPulumiSetup(repositoryRoot, variables) m := Model{ initialScreen: wizardScreen, DotenvFile: dotenvFile, variables: variables, contents: contents, SuccessCmd: tea.Quit, ShowAllPrompts: showAllPrompts, NeedsPulumiLogin: needsPulumi, PulumiAlreadyLoggedIn: pulumiLoggedIn, NeedsPulumiPassphrase: needsPassphrase, } finalModel, err := tui.Run(m, tea.WithAltScreen(), tea.WithContext(cmd.Context())) if err != nil { return err } if finalM, ok := finalModel.(tui.InterruptibleModel); ok { if m, ok := finalM.Model.(Model); ok { if m.err != nil { return m.err } if m.pulumiModel != nil && m.pulumiModel.err != nil { return m.pulumiModel.err } } } _ = state.UpdateAfterDotenvSetup(repositoryRoot) return nil }, }
View Source
var UpdateCmd = &cobra.Command{ Use: "update", Short: "🔄 Automatically update DataRobot credentials", Long: `Automatically update your '.env' file with fresh DataRobot credentials. This command will: • Refresh your DataRobot API credentials • Update environment variables automatically • Preserve your existing custom settings 💡 Use this when your credentials expire or you need to refresh your connection.`, PreRunE: auth.EnsureAuthenticatedE, Run: func(_ *cobra.Command, _ []string) { dotenv, err := ensureInRepoWithDotenv() if err != nil { os.Exit(1) } _, _, err = updateDotenvFile(dotenv) if err != nil { log.Error(err) os.Exit(1) } }, }
View Source
var ValidateCmd = &cobra.Command{ Use: "validate", Short: "✅ Validate '.env' and environment variable configuration", Run: func(_ *cobra.Command, _ []string) { dotenv, err := ensureInRepoWithDotenv() if err != nil { os.Exit(1) } repoRoot := filepath.Dir(dotenv) dotenvFileLines, _ := readDotenvFile(dotenv) parsedVars := envbuilder.ParseVariablesOnly(dotenvFileLines) result := envbuilder.ValidateEnvironment(repoRoot, parsedVars) varStyle := lipgloss.NewStyle().Foreground(tui.DrPurple).Bold(true) valueStyle := lipgloss.NewStyle().Foreground(tui.DrGreen) fmt.Println("\nValidating required variables:") for _, valResult := range result.Results { if valResult.Valid { fmt.Printf(" %s: %s\n", varStyle.Render(valResult.Field), valueStyle.Render(valResult.Value)) } } if result.HasErrors() { fmt.Println("\nValidation errors:") for _, valResult := range result.Results { if !valResult.Valid { fmt.Printf("\n%s: Required variable %s is not set\n", tui.ErrorStyle.Render("Error"), varStyle.Render(valResult.Field)) if valResult.Help != "" { fmt.Printf(" Description: %s\n", valResult.Help) } fmt.Println(" Set this variable in your '.env' file or run `dr dotenv setup` to configure it.") } } os.Exit(1) } fmt.Println("\nValidation passed: all required variables are set.") }, }
Functions ¶
func CheckPulumiSetup ¶ added in v0.2.55
func CheckPulumiSetup(dir string, variables []envbuilder.Variable) (needsSetup, alreadyLoggedIn, needsPassphrase bool)
CheckPulumiSetup returns whether the Pulumi setup screen should be shown, whether the user is already logged in, and whether a passphrase needs to be configured. Call this before starting the dotenv TUI and set the corresponding Model fields.
func ValidateAndEditIfNeeded ¶ added in v0.2.29
func ValidateAndEditIfNeeded() error
ValidateAndEditIfNeeded validates the .env file and prompts for editing if validation fails. Returns nil if validation passes or editing completes successfully. Returns an error if validation or editing fails.
Types ¶
type Model ¶
type Model struct {
DotenvFile string
SuccessCmd tea.Cmd
ShowAllPrompts bool // When true, show all prompts regardless of defaults
NeedsPulumiLogin bool // Set by callers before Init(); true when login or passphrase setup is needed
PulumiAlreadyLoggedIn bool // Set by callers; when true, Pulumi screen skips backend selection
NeedsPulumiPassphrase bool // Set by callers; when true, passphrase prompt is shown after login
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.