dotenv

package
v0.2.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

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: func(cmd *cobra.Command, _ []string) error {
		return auth.EnsureAuthenticatedE(cmd.Context())
	},
	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)

		m := Model{
			initialScreen: wizardScreen,
			DotenvFile:    dotenvFile,
			variables:     variables,
			contents:      contents,
			SuccessCmd:    tea.Quit,
		}
		_, err = tui.Run(m, tea.WithAltScreen(), tea.WithContext(cmd.Context()))
		if err != nil {
			return err
		}

		_ = state.UpdateAfterDotenvSetup()

		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: func(cmd *cobra.Command, _ []string) error {
		return auth.EnsureAuthenticatedE(cmd.Context())
	},
	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 against required settings.",
	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 Cmd

func Cmd() *cobra.Command

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
	// contains filtered or unexported fields
}

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model) View

func (m Model) View() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL