on 94de6bc help sign in
crush/internal/cmd/update_providers.go
60 lines 1.5 kB history raw
1package cmd
3import (
4 "fmt"
5 "log/slog"
7 "charm.land/lipgloss/v2"
8 "github.com/charmbracelet/crush/internal/config"
9 "github.com/charmbracelet/x/exp/charmtone"
10 "github.com/spf13/cobra"
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
21# Update providers from a custom URL
22crush update-providers https://example.com/
24# Update providers from a local file
25crush update-providers /path/to/local-providers.json
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))
34 var pathOrUrl string
35 if len(args) > 0 {
36 pathOrUrl = args[0]
37 }
39 if err := config.UpdateProviders(pathOrUrl); err != nil {
40 return err
41 }
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.")
57 fmt.Printf("%s\n%s\n\n", headerStyle.Render(), textStyle.Render())
58 return nil
59 },