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.DirectoryView on GitHub (pinned to 4d089f9550)
Solutions
- Pass --file, --directory, or both when invoking gum file
- Set File: true (or Directory: true) on the Options struct before calling Run
- 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
- Always pass --file and/or --directory to gum file
- In Go set File or Directory on the Options struct before Run
- Audit wrapper scripts for dropped flags
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
- no file selected
- file not found: %w
- no options provided, see `gum choose --help`
- nothing selected
- invalid option format: %q
AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31).
Data as JSON: /api/errors/8279c5408a788dc2.
Report an issue: GitHub.