dotenv

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 28 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 {
		if viper.GetBool("debug") {
			f, err := tea.LogToFile("tea-debug.log", "debug")
			if err != nil {
				fmt.Println("fatal:", err)
				os.Exit(1)
			}
			defer f.Close()
		}

		cwd, err := os.Getwd()
		if err != nil {
			return err
		}

		dotenvFile := filepath.Join(cwd, ".env")
		templateLines, templateFileUsed := readTemplate(dotenvFile)

		variables := parseVariablesOnly(templateLines)
		contents := strings.Join(templateLines, "")

		screen := editorScreen
		if repo.IsInRepo() {
			if handleExtraEnvVars(variables) {
				screen = wizardScreen
			}
		}

		m := Model{
			initialScreen:  screen,
			DotenvFile:     dotenvFile,
			DotenvTemplate: templateFileUsed,
			variables:      variables,
			contents:       contents,
			SuccessCmd:     tea.Quit,
		}
		p := tea.NewProgram(
			tui.NewInterruptibleModel(m),
			tea.WithAltScreen(),
			tea.WithContext(cmd.Context()),
		)
		_, err = p.Run()

		return err
	},
}
View Source
var SetupCmd = &cobra.Command{
	Use:   "setup",
	Short: "Edit .env file using setup wizard",
	RunE: func(cmd *cobra.Command, _ []string) error {
		if viper.GetBool("debug") {
			f, err := tea.LogToFile("tea-debug.log", "debug")
			if err != nil {
				fmt.Println("fatal:", err)
				os.Exit(1)
			}
			defer f.Close()
		}

		cwd, err := os.Getwd()
		if err != nil {
			return err
		}

		dotenvFile := filepath.Join(cwd, ".env")
		templateLines, templateFileUsed := readTemplate(dotenvFile)
		variables, contents, _ := variablesFromTemplate(templateLines)

		m := Model{
			initialScreen:  wizardScreen,
			DotenvFile:     dotenvFile,
			DotenvTemplate: templateFileUsed,
			variables:      variables,
			contents:       contents,
			SuccessCmd:     tea.Quit,
		}
		p := tea.NewProgram(
			tui.NewInterruptibleModel(m),
			tea.WithAltScreen(),
			tea.WithContext(cmd.Context()),
		)
		_, err = p.Run()

		return err
	},
}
View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Automatically update Datarobot credentials in .env file",
	Long:  "Automatically populate .env file with fresh Datarobot credentials",
	PreRunE: func(cmd *cobra.Command, _ []string) error {
		return auth.EnsureAuthenticatedE(cmd.Context())
	},
	Run: func(_ *cobra.Command, _ []string) {
		dotenvFile := ".env"

		_, _, _, err := writeUsingTemplateFile(dotenvFile)
		if err != nil {
			log.Error(err)
		}
	},
}

Functions

func Cmd

func Cmd() *cobra.Command

Types

type Model

type Model struct {
	DotenvFile     string
	DotenvTemplate 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

type Variables added in v0.2.1

type Variables []variable

Jump to

Keyboard shortcuts

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