1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5// Package completion provides shell completion helpers for CLI commands.
6package completion
7
8import (
9 "git.secluded.site/lune/internal/config"
10 "github.com/spf13/cobra"
11)
12
13// Areas returns area keys from config for shell completion.
14func Areas(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
15 cfg, err := config.Load()
16 if err != nil {
17 return nil, cobra.ShellCompDirectiveError
18 }
19
20 keys := make([]string, len(cfg.Areas))
21 for i, a := range cfg.Areas {
22 keys[i] = a.Key
23 }
24
25 return keys, cobra.ShellCompDirectiveNoFileComp
26}
27
28// Goals returns all goal keys across all areas for shell completion.
29func Goals(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
30 cfg, err := config.Load()
31 if err != nil {
32 return nil, cobra.ShellCompDirectiveError
33 }
34
35 totalGoals := 0
36 for _, a := range cfg.Areas {
37 totalGoals += len(a.Goals)
38 }
39
40 keys := make([]string, 0, totalGoals)
41
42 for _, a := range cfg.Areas {
43 for _, g := range a.Goals {
44 keys = append(keys, g.Key)
45 }
46 }
47
48 return keys, cobra.ShellCompDirectiveNoFileComp
49}
50
51// Notebooks returns notebook keys from config for shell completion.
52func Notebooks(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
53 cfg, err := config.Load()
54 if err != nil {
55 return nil, cobra.ShellCompDirectiveError
56 }
57
58 keys := make([]string, len(cfg.Notebooks))
59 for i, n := range cfg.Notebooks {
60 keys[i] = n.Key
61 }
62
63 return keys, cobra.ShellCompDirectiveNoFileComp
64}
65
66// Habits returns habit keys from config for shell completion.
67func Habits(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
68 cfg, err := config.Load()
69 if err != nil {
70 return nil, cobra.ShellCompDirectiveError
71 }
72
73 keys := make([]string, len(cfg.Habits))
74 for i, h := range cfg.Habits {
75 keys[i] = h.Key
76 }
77
78 return keys, cobra.ShellCompDirectiveNoFileComp
79}
80
81// Relationships returns relationship strength options for shell completion.
82func Relationships(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
83 return []string{
84 "family",
85 "intimate-friends",
86 "close-friends",
87 "casual-friends",
88 "acquaintances",
89 "business-contacts",
90 "almost-strangers",
91 }, cobra.ShellCompDirectiveNoFileComp
92}