1package cmd
2
3import (
4 "fmt"
5 "log/slog"
6
7 "github.com/charmbracelet/crush/internal/config"
8 "github.com/charmbracelet/lipgloss/v2"
9 "github.com/charmbracelet/x/exp/charmtone"
10 "github.com/spf13/cobra"
11)
12
13var updateProvidersCmd = &cobra.Command{
14 Use: "update-providers [path-or-url]",
15 Short: "Update providers",
16 Long: `Update the list of providers from a specified local path or remote URL.`,
17 Example: `
18# Update providers remotely from Catwalk
19crush update-providers
20
21# Update providers from a custom URL
22crush update-providers https://example.com/
23
24# Update providers from a local file
25crush update-providers /path/to/local-providers.json
26
27# Update providers from embedded version
28crush update-providers embedded
29`,
30 RunE: func(cmd *cobra.Command, args []string) error {
31 // NOTE(@andreynering): We want to skip logging output do stdout here.
32 slog.SetDefault(slog.New(slog.DiscardHandler))
33
34 var pathOrUrl string
35 if len(args) > 0 {
36 pathOrUrl = args[0]
37 }
38
39 if err := config.UpdateProviders(pathOrUrl); err != nil {
40 return err
41 }
42
43 // NOTE(@andreynering): This style is more-or-less copied from Fang's
44 // error message, adapted for success.
45 headerStyle := lipgloss.NewStyle().
46 Foreground(charmtone.Butter).
47 Background(charmtone.Guac).
48 Bold(true).
49 Padding(0, 1).
50 Margin(1).
51 MarginLeft(2).
52 SetString("SUCCESS")
53 textStyle := lipgloss.NewStyle().
54 MarginLeft(2).
55 SetString("Providers updated successfully.")
56
57 fmt.Printf("%s\n%s\n\n", headerStyle.Render(), textStyle.Render())
58 return nil
59 },
60}