Skip to content

Commit a23de68

Browse files
committed
chore: update completions & help
1 parent 35fc152 commit a23de68

6 files changed

Lines changed: 73 additions & 47 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ For more info check out the [help articles](https://gith.featurebase.app/help).
183183

184184
- [x] Change UI accent color
185185

186+
- [x] Change fetch behaviour on Init
187+
186188
## Contributing
187189

188190
Contributions are welcome, please use [conventional commits](https://www.conventionalcommits.org/) for a constant commit message style.

completions/_gith

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ _gith() {
1515
_arguments \
1616
'1:subcommand:(show reset path update help tag)' \
1717
'--flavor[Catppuccin flavor]:(latte frappe macchiato mocha)' \
18-
'--accent[Catppuccin accent]:(rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender)'
18+
'--accent[Catppuccin accent]:(rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender)' \
19+
'--initFetch[Init fetch behaviour]:(always quick never)'
1920
;;
2021
add)
2122
_arguments '1:subcommand:(remote)'

completions/gith.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ _gith() {
4646
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
4747
return 0
4848
;;
49+
--initFetch)
50+
opts="always quick never"
51+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
52+
return 0
53+
;;
4954
esac
5055
}
5156
complete -F _gith gith

completions/gith.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ complete -c gith -n "__fish_seen_subcommand_from version" -a "check" -d "Check f
55
complete -c gith -n "__fish_seen_subcommand_from config" -a "show reset path update help" -d "Config commands"
66
complete -c gith -n "__fish_seen_subcommand_from config update" -l flavor -d "Catppuccin flavor" -a "latte frappe macchiato mocha"
77
complete -c gith -n "__fish_seen_subcommand_from config update" -l accent -d "Catppuccin accent" -a "rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender gray"
8+
complete -c gith -n "__fish_seen_subcommand_from config update" -l initFetch -d "Init fetch behaviour" -a "always quick never"
89
complete -c gith -n "__fish_seen_subcommand_from add" -a "remote" -d "Quick Select: Add Remote"
910
complete -c gith -n "__fish_seen_subcommand_from push" -a "tag" -d "Quick Select: Push Tag"
1011
complete -c gith -n "__fish_seen_subcommand_from undo" -a "commit" -d "Quick Select: Status"

internal/utils.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ complete -c gith -n "__fish_seen_subcommand_from version" -a "check" -d "Check f
424424
complete -c gith -n "__fish_seen_subcommand_from config" -a "show reset path update help" -d "Config commands"
425425
complete -c gith -n "__fish_seen_subcommand_from config update" -l flavor -d "Catppuccin flavor" -a "latte frappe macchiato mocha"
426426
complete -c gith -n "__fish_seen_subcommand_from config update" -l accent -d "Catppuccin accent" -a "rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender gray"
427+
complete -c gith -n "__fish_seen_subcommand_from config update" -l initFetch -d "Init fetch behaviour" -a "always quick never"
427428
complete -c gith -n "__fish_seen_subcommand_from add" -a "remote" -d "Quick Select: Add Remote"
428429
complete -c gith -n "__fish_seen_subcommand_from push" -a "tag" -d "Quick Select: Push Tag"
429430
complete -c gith -n "__fish_seen_subcommand_from undo" -a "commit" -d "Quick Select: Status"
@@ -477,6 +478,11 @@ _gith() {
477478
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
478479
return 0
479480
;;
481+
--initFetch)
482+
opts="always quick never"
483+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
484+
return 0
485+
;;
480486
esac
481487
}
482488
complete -F _gith gith
@@ -499,7 +505,8 @@ _gith() {
499505
_arguments \
500506
'1:subcommand:(show reset path update help tag)' \
501507
'--flavor[Catppuccin flavor]:(latte frappe macchiato mocha)' \
502-
'--accent[Catppuccin accent]:(rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender)'
508+
'--accent[Catppuccin accent]:(rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender)' \
509+
'--initFetch[Init fetch behaviour]:(always quick never)'
503510
;;
504511
add)
505512
_arguments '1:subcommand:(remote)'

main.go

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,33 @@ func handleConfigCommand() error {
282282
}
283283

284284
func printConfigUsage() error {
285-
fmt.Println("Config commands:")
286-
fmt.Println(" gith config show - Show current configuration")
287-
fmt.Println(" gith config reset - Reset configuration to defaults")
288-
fmt.Println(" gith config path - Show configuration file path")
289-
fmt.Println(" gith config update [--flavor=<flavor>] [--accent=<accent>] - Update configuration")
290-
fmt.Println(" <flavor> can be any of the catppuccin flavors (case insensitive)")
291-
fmt.Println(" <accent> can be any of the catppuccin accents (case insensitive)")
285+
helpText := `
286+
Config commands:
287+
gith config show - Show current configuration
288+
gith config reset - Reset configuration to defaults
289+
gith config path - Show configuration file path
290+
291+
gith config update [--flavor=<flavor>] [--accent=<accent>] [--initFetch=<initFetch>]
292+
Update your configuration options. Flags are optional and can be combined.
293+
294+
--flavor=<flavor>
295+
Set the Catppuccin flavor (case insensitive). Available options:
296+
Latte, Frappe, Macchiato, Mocha
297+
298+
--accent=<accent>
299+
Set the Catppuccin accent color (case insensitive). Available options:
300+
Rosewater, Flamingo, Pink, Mauve, Red, Maroon, Peach, Yellow, Green,
301+
Teal, Blue, Sapphire, Sky, Lavender, Gray
302+
303+
--initFetch=<initFetch>
304+
Set fetch behavior on init. Available options:
305+
always - always fetch on init
306+
quick - fetch only for full load, skip for quick selects
307+
never - never fetch on init
308+
`
309+
310+
fmt.Println(helpText)
311+
292312
return nil
293313
}
294314

@@ -299,8 +319,9 @@ func showConfig() error {
299319
}
300320

301321
fmt.Printf("Current configuration:\n")
302-
fmt.Printf(" Flavor: %s\n", cfg.Flavor)
303-
fmt.Printf(" Accent: %s\n", cfg.Accent)
322+
fmt.Printf(" Flavor: %s\n", cfg.Flavor)
323+
fmt.Printf(" Accent: %s\n", cfg.Accent)
324+
fmt.Printf(" Init Behaviour: %s\n", cfg.InitBehaviour)
304325
return nil
305326
}
306327

@@ -314,46 +335,35 @@ func updateConfig() error {
314335
return fmt.Errorf("failed to load config: %w", err)
315336
}
316337

317-
// TODO: when adding more to configure, make sure to handle this automatically
318-
319-
first := strings.ToLower(os.Args[3])
320-
second := ""
321-
322-
if len(os.Args) >= 5 {
323-
second = strings.ToLower(os.Args[4])
324-
}
338+
args := os.Args[3:]
339+
for _, arg := range args {
340+
arg = strings.ToLower(arg)
325341

326-
if flavor, found := strings.CutPrefix(first, "--flavor="); found {
327-
if config.IsValidFlavor(flavor) {
328-
cfg.Flavor = flavor
329-
} else {
330-
return fmt.Errorf("not a valid flavor: %s\nlist of valid flavors: %s", flavor, config.GetAvailableFlavors())
331-
}
332-
} else if accent, found := strings.CutPrefix(first, "--accent="); found {
333-
if config.IsValidAccent(accent) {
334-
cfg.Accent = accent
335-
} else {
336-
return fmt.Errorf("not a valid accent: %s\nlist of valid accent: %s", accent, config.GetAvailableAccents())
337-
}
338-
} else {
339-
return fmt.Errorf("'%s' is not a valid flag\nRun 'gith config help' to see valid flags", strings.TrimPrefix(strings.Split(first, "=")[0], "--"))
340-
}
342+
switch {
343+
case strings.HasPrefix(arg, "--flavor="):
344+
val := strings.TrimPrefix(arg, "--flavor=")
345+
if !config.IsValidFlavor(val) {
346+
return fmt.Errorf("not a valid flavor: %s\nvalid flavors: %s", val, strings.Join(config.GetAvailableFlavors(), ", "))
347+
}
348+
cfg.Flavor = val
341349

342-
if second != "" {
343-
if flavor, found := strings.CutPrefix(second, "--flavor="); found {
344-
if config.IsValidFlavor(flavor) {
345-
cfg.Flavor = flavor
346-
} else {
347-
return fmt.Errorf("not a valid flavor: %s\nlist of valid flavors: %s", flavor, config.GetAvailableFlavors())
350+
case strings.HasPrefix(arg, "--accent="):
351+
val := strings.TrimPrefix(arg, "--accent=")
352+
if !config.IsValidAccent(val) {
353+
return fmt.Errorf("not a valid accent: %s\nvalid accents: %s", val, strings.Join(config.GetAvailableAccents(), ", "))
348354
}
349-
} else if accent, found := strings.CutPrefix(second, "--accent="); found {
350-
if config.IsValidAccent(accent) {
351-
cfg.Accent = accent
352-
} else {
353-
return fmt.Errorf("not a valid accent: %s\nlist of valid accent: %s", accent, config.GetAvailableAccents())
355+
cfg.Accent = val
356+
357+
case strings.HasPrefix(arg, "--initfetch="):
358+
val := strings.TrimPrefix(arg, "--initfetch=")
359+
valid := map[string]bool{"always": true, "quick": true, "never": true}
360+
if !valid[val] {
361+
return fmt.Errorf("not a valid initFetch: %s\nvalid options: always, quick, never", val)
354362
}
355-
} else {
356-
return fmt.Errorf("'%s' is not a valid flag\nRun 'gith config help' to see valid flags", strings.TrimPrefix(strings.Split(first, "=")[0], "--"))
363+
cfg.InitBehaviour = val
364+
365+
default:
366+
return fmt.Errorf("'%s' is not a valid flag\nRun 'gith config help' to see valid flags", strings.Split(arg, "=")[0])
357367
}
358368
}
359369

0 commit comments

Comments
 (0)