charmbracelet/gum · error

at least one between --file and --directory must be set

Error message

at least one between --file and --directory must be set

What it means

gum file requires the caller to enable at least one selection mode: --file and/or --directory. With both false there is nothing the picker is allowed to select, so Run rejects the invocation immediately.

Source

Thrown at file/command.go:19

package file

import (
	"errors"
	"fmt"
	"os"
	"path/filepath"

	"charm.land/bubbles/v2/filepicker"
	"charm.land/bubbles/v2/help"
	tea "charm.land/bubbletea/v2"
	"charm.land/gum/v2/internal/timeout"
	"charm.land/gum/v2/style"
)

// Run is the interface to picking a file.
func (o Options) Run() error {
	if !o.File && !o.Directory {
		return errors.New("at least one between --file and --directory must be set")
	}

	if o.Path == "" {
		o.Path = "."
	}

	path, err := filepath.Abs(o.Path)
	if err != nil {
		return fmt.Errorf("file not found: %w", err)
	}

	fp := filepicker.New()
	fp.CurrentDirectory = path
	fp.Path = path
	fp.SetHeight(o.Height)
	fp.AutoHeight = o.Height == 0
	fp.Cursor = o.Cursor
	fp.DirAllowed = o.Directory

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Pass --file, --directory, or both when invoking gum file
  2. Set File: true (or Directory: true) on the Options struct before calling Run
  3. Update wrapper scripts to forward the mode flags

Example fix

// before
gum file  # error
// after
gum file --file
// Go
// before: gum.FileOptions{}
// after:  gum.FileOptions{File: true}
Defensive patterns

Strategy: validation

Validate before calling

null

Prevention

When it happens

Trigger: Options.Run() is invoked with o.File == false && o.Directory == false — the gum file command constructed programmatically (or via flags) without either mode flag set.

Common situations: Building gum.Options in Go and forgetting to set File or Directory fields; stripping flags when wrapping gum in a script; version changes where defaults shifted.

Related errors


AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31). Data as JSON: /api/errors/8279c5408a788dc2. Report an issue: GitHub.