Add shell completion

This commit is contained in:
2026-07-28 20:31:44 +02:00
parent ef32aa473e
commit e89c524438
5 changed files with 371 additions and 16 deletions

48
main.go
View File

@@ -11,31 +11,47 @@ import (
)
func main() {
if handled, err := handleCompletionCommand(os.Args[1:], os.Stdout); handled {
if err != nil {
exitf("%v", err)
}
return
}
defaults := defaultConfig()
defaultConfigPath, err := configPath()
if err != nil {
exitf("configuration: %v", err)
}
flag.Usage = func() {
writeCLIHelp(flag.CommandLine.Output(), defaults, defaultConfigPath)
}
if len(os.Args) == 2 && os.Args[1] == "help" {
flag.Usage()
return
}
var (
configFile = flag.String("config", defaultConfigPath, "TOML configuration file")
repo = flag.String("repo", "", "optional GitHub repository filter as owner/name (or GH_REPO)")
poll = flag.Duration("poll", defaults.RefreshInterval.Duration, "refresh interval")
showAll = flag.Bool("all", defaults.ShowAll, "show all open PRs in --repo, not only PRs assigned to you")
limit = flag.Int("limit", defaults.Limit, "maximum open PRs to load (1-1000)")
endpoint = flag.String("endpoint", defaults.Endpoint, "GitHub GraphQL endpoint")
theme = flag.String("theme", defaults.Theme, "color theme name (including custom, catppuccin, gruvbox, one-dark-pro, and github)")
foldResolved = flag.Bool("fold-resolved", defaults.Display.FoldResolved, "start resolved threads folded")
listWidth = flag.Int("thread-list-width", defaults.Display.ThreadListWidthPercent, "thread list width as terminal percentage (20-60)")
dashboardMode = flag.String("dashboard-mode", defaults.Display.DashboardMode, "dashboard navigation: intermediate or hotkey")
compactReviews = flag.Bool("compact-reviews", defaults.Display.CompactReviews, "aggregate submitted review history")
pathScroll = flag.Bool("path-scroll", defaults.Paths.Scroll, "scroll truncated paths")
pathScrollRate = flag.Duration("path-scroll-interval", defaults.Paths.ScrollInterval.Duration, "path scrolling interval")
cacheEnabled = flag.Bool("cache", defaults.Cache.Enabled, "enable local read cache fallback")
cacheMaxAge = flag.Duration("cache-max-age", defaults.Cache.MaxAge.Duration, "maximum offline cache age (0 disables expiry)")
cacheDir = flag.String("cache-dir", defaults.Cache.Directory, "local read cache directory")
editorMode = flag.String("editor-mode", defaults.Editing.Mode, "description editor mode: standard or vim")
repo = flag.String("repo", "", "limit pull requests to an owner/repository")
poll = flag.Duration("poll", defaults.RefreshInterval.Duration, "base interval between GitHub refreshes")
showAll = flag.Bool("all", defaults.ShowAll, "show every open PR in --repo instead of only assigned PRs")
limit = flag.Int("limit", defaults.Limit, "maximum number of open pull requests to load")
endpoint = flag.String("endpoint", defaults.Endpoint, "GitHub GraphQL API endpoint")
theme = flag.String("theme", defaults.Theme, "built-in or custom color theme")
foldResolved = flag.Bool("fold-resolved", defaults.Display.FoldResolved, "start resolved review threads folded")
listWidth = flag.Int("thread-list-width", defaults.Display.ThreadListWidthPercent, "thread-list width as a percentage of the terminal")
dashboardMode = flag.String("dashboard-mode", defaults.Display.DashboardMode, "open the dashboard by hotkey or as an intermediate screen")
compactReviews = flag.Bool("compact-reviews", defaults.Display.CompactReviews, "aggregate repeated submitted-review entries")
pathScroll = flag.Bool("path-scroll", defaults.Paths.Scroll, "scroll file paths that do not fit")
pathScrollRate = flag.Duration("path-scroll-interval", defaults.Paths.ScrollInterval.Duration, "interval between file-path scroll steps")
cacheEnabled = flag.Bool("cache", defaults.Cache.Enabled, "enable the local read cache and offline fallback")
cacheMaxAge = flag.Duration("cache-max-age", defaults.Cache.MaxAge.Duration, "oldest cache entry accepted for offline fallback")
cacheDir = flag.String("cache-dir", defaults.Cache.Directory, "local read-cache directory")
editorMode = flag.String("editor-mode", defaults.Editing.Mode, "description editor mode")
)
flag.Parse()
if flag.NArg() != 0 {
exitf("unexpected argument %q; run 'diple --help' for usage", flag.Arg(0))
}
visited := map[string]bool{}
flag.Visit(func(item *flag.Flag) { visited[item.Name] = true })