Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ tmp
coverage.txt

# Tea
tea-debug.log
dr-tui-debug.log
17 changes: 8 additions & 9 deletions cmd/dotenv/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package dotenv

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -44,12 +43,12 @@ var EditCmd = &cobra.Command{
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")
cleanup, err := tui.SetupDebugLogging()
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
return err
}
defer f.Close()

defer cleanup()
}

cwd, err := os.Getwd()
Expand Down Expand Up @@ -87,12 +86,12 @@ var SetupCmd = &cobra.Command{
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")
cleanup, err := tui.SetupDebugLogging()
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
return err
}
defer f.Close()

defer cleanup()
}

cwd, err := os.Getwd()
Expand Down
10 changes: 4 additions & 6 deletions cmd/templates/setup/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ package setup

import (
"context"
"fmt"
"os"

tea "github.com/charmbracelet/bubbletea"
"github.com/datarobot/cli/tui"
Expand All @@ -37,12 +35,12 @@ the template configuration process step by step.`,
// RunTea starts the template setup TUI
func RunTea(ctx context.Context) error {
if viper.GetBool("debug") {
f, err := tea.LogToFile("tea-debug.log", "debug")
cleanup, err := tui.SetupDebugLogging()
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
return err
}
defer f.Close()

defer cleanup()
}

m := NewModel()
Expand Down
32 changes: 32 additions & 0 deletions tui/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 DataRobot, Inc. and its affiliates.
// All rights reserved.
// DataRobot, Inc. Confidential.
// This is unpublished proprietary source code of DataRobot, Inc.
// and its affiliates.
// The copyright notice above does not evidence any actual or intended
// publication of such source code.

package tui

import (
"fmt"
"os"

tea "github.com/charmbracelet/bubbletea"
)

// DebugLogFile is the filename for TUI debug logs
const DebugLogFile = "dr-tui-debug.log"

// SetupDebugLogging configures debug logging for the TUI if debug mode is enabled.
// It should be called at the start of TUI programs when debug logging is needed.
// Returns a cleanup function that should be deferred to close the log file.
func SetupDebugLogging() (cleanup func(), err error) {
f, err := tea.LogToFile(DebugLogFile, "debug")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}

return func() { f.Close() }, nil
}