wrds-download

TUI/CLI tool for browsing and downloading WRDS data
Log | Files | Refs | README

tui.go (821B)


      1 package cmd
      2 
      3 import (
      4 	"fmt"
      5 	"os"
      6 
      7 	tea "github.com/charmbracelet/bubbletea"
      8 	"github.com/louloulibs/wrds-download/internal/config"
      9 	"github.com/louloulibs/wrds-download/internal/tui"
     10 	"github.com/spf13/cobra"
     11 )
     12 
     13 var tuiCmd = &cobra.Command{
     14 	Use:   "tui",
     15 	Short: "Launch the interactive TUI browser",
     16 	RunE:  runTUI,
     17 }
     18 
     19 func init() {
     20 	rootCmd.AddCommand(tuiCmd)
     21 }
     22 
     23 func runTUI(cmd *cobra.Command, args []string) error {
     24 	config.ApplyCredentials()
     25 
     26 	// Always start in login mode so the user controls when the
     27 	// connection (and any 2FA prompt) happens.
     28 	m := tui.NewAppNoClient()
     29 	p := tea.NewProgram(m, tea.WithAltScreen())
     30 	final, err := p.Run()
     31 	if err != nil {
     32 		fmt.Fprintln(os.Stderr, err)
     33 		os.Exit(1)
     34 	}
     35 	if a, ok := final.(*tui.App); ok && a.Err() != "" {
     36 		fmt.Fprintln(os.Stderr, a.Err())
     37 	}
     38 	return nil
     39 }