provider

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCommand = cli.Command{
	Name:  "add",
	Usage: "Interactively add an AI provider for commit generation",
	Action: func(_ context.Context, _ *cli.Command) error {
		return runAdd()
	},
}
View Source
var ListCommand = cli.Command{
	Name:  "list",
	Usage: "List all configured AI providers",
	Action: func(_ context.Context, _ *cli.Command) error {
		cfg, err := config.LoadConfig()
		if err != nil {
			return cli.Exit(fmt.Errorf("load config: %w", err), 1)
		}

		if cfg.CommitGen == nil || len(cfg.CommitGen.Providers) == 0 {
			fmt.Println(colors.Yellow("No providers configured. Run `gixy provider add` to add one."))
			return nil
		}

		keys := make([]string, 0, len(cfg.CommitGen.Providers))
		for k := range cfg.CommitGen.Providers {
			keys = append(keys, k)
		}
		sort.Strings(keys)

		fmt.Println()
		fmt.Printf("    %-15s %-15s %-25s %s\n", "NAME", "PROVIDER", "MODEL", "HOST")
		fmt.Println()
		for _, k := range keys {
			entry := cfg.CommitGen.Providers[k]
			marker := " "
			paddedName := fmt.Sprintf("%-15s", k)
			nameStr := colors.Cyan(paddedName)
			if k == cfg.CommitGen.Active {
				marker = colors.Green("*")
				nameStr = colors.Green(paddedName)
			}
			fmt.Printf("  %s %s %-15s %-25s %s\n", marker, nameStr, entry.Provider, entry.Model, entry.Host)
		}
		fmt.Println()
		return nil
	},
}
View Source
var RemoveCommand = cli.Command{
	Name:      "remove",
	Aliases:   []string{"delete"},
	Usage:     "Remove a configured AI provider",
	ArgsUsage: "<name>",
	Action: func(_ context.Context, cmd *cli.Command) error {
		if cmd.Args().Len() != 1 {
			return cli.Exit(colors.Red("usage: gixy provider remove <name>"), 1)
		}
		name := cmd.Args().Get(0)

		cfg, err := config.LoadConfig()
		if err != nil {
			return cli.Exit(fmt.Errorf("load config: %w", err), 1)
		}

		if cfg.CommitGen == nil {
			return cli.Exit(colors.Red(fmt.Sprintf("provider %q not found", name)), 1)
		}
		if _, exists := cfg.CommitGen.Providers[name]; !exists {
			return cli.Exit(colors.Red(fmt.Sprintf("provider %q not found", name)), 1)
		}

		delete(cfg.CommitGen.Providers, name)
		if cfg.CommitGen.Active == name {
			cfg.CommitGen.Active = ""
		}

		if err := config.SaveConfig(cfg); err != nil {
			return cli.Exit(fmt.Errorf("save config: %w", err), 1)
		}

		fmt.Println(colors.Green(fmt.Sprintf("Provider %q removed.", name)))
		if cfg.CommitGen.Active == "" && len(cfg.CommitGen.Providers) > 0 {
			fmt.Println(colors.Yellow("No active provider set. Run `gixy provider use <name>` to set one."))
		}
		return nil
	},
}
View Source
var UseCommand = cli.Command{
	Name:      "use",
	Usage:     "Set the active AI provider",
	ArgsUsage: "<name>",
	Action: func(_ context.Context, cmd *cli.Command) error {
		if cmd.Args().Len() != 1 {
			return cli.Exit(colors.Red("usage: gixy provider use <name>"), 1)
		}
		name := cmd.Args().Get(0)

		cfg, err := config.LoadConfig()
		if err != nil {
			return cli.Exit(fmt.Errorf("load config: %w", err), 1)
		}

		if cfg.CommitGen == nil {
			return cli.Exit(colors.Red(fmt.Sprintf("provider %q not found", name)), 1)
		}
		if _, exists := cfg.CommitGen.Providers[name]; !exists {
			return cli.Exit(colors.Red(fmt.Sprintf("provider %q not found", name)), 1)
		}

		cfg.CommitGen.Active = name

		if err := config.SaveConfig(cfg); err != nil {
			return cli.Exit(fmt.Errorf("save config: %w", err), 1)
		}

		fmt.Println(colors.Green(fmt.Sprintf("Active provider set to %q.", name)))
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL