cmd

package
v0.0.0-...-fa94b45 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Log is the globally configured zerolog logger instance used throughout the cmd package.
	// It's initialized in rootCmd's PersistentPreRunE based on the --log-level flag.
	Log zerolog.Logger
)

Functions

func Execute

func Execute()

Execute is the main entry point for the Cobra CLI application. It parses command-line arguments, executes the appropriate command (rootCmd or one of its subcommands), handles flag parsing, and manages error reporting. This function is typically called directly from main.main().

func NewCreateCmdRunnerForTest

func NewCreateCmdRunnerForTest(cp ConfigProvider, llmClient llm.Client, mcpClient MCPClient, pm ProjectMapper, ir IssueTypeResolver) *createCmdRunner

NewCreateCmdRunnerForTest creates a runner with explicitly provided dependencies for testing.

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd creates a new instance of the root command, configured for testing or embedding. It mirrors the setup of the package-level rootCmd.

Types

type ConfigProvider

type ConfigProvider interface {
	LoadConfig() (*config.AppConfig, error)
	LoadLinks() (*config.LinksConfig, error)
	LoadSystemPrompt() (string, error)
	LoadContext() (string, error)
	GetAPIKey() (string, error)
	CreateDefaultConfigFiles(configDir string) error // Added for config init
	EnsureConfigDir() (string, error)                // Added for config locate
}

ConfigProvider defines an interface for components that load various configuration aspects of the Ticketron application, such as the main config, project links, prompts, context, and API keys. It also includes methods for managing the configuration directory and default files. This abstraction allows for easier testing by mocking configuration loading behavior.

type DefaultConfigProvider

type DefaultConfigProvider struct{}

defaultConfigProvider implements the ConfigProvider interface using the actual config package functions. Exported for potential use in tests directly.

func (*DefaultConfigProvider) CreateDefaultConfigFiles

func (p *DefaultConfigProvider) CreateDefaultConfigFiles(configDir string) error

CreateDefaultConfigFiles calls the underlying config function to create default files. It ignores the configDir parameter as the underlying function determines the path.

func (*DefaultConfigProvider) EnsureConfigDir

func (p *DefaultConfigProvider) EnsureConfigDir() (string, error)

EnsureConfigDir calls the underlying config function to ensure the config directory exists.

func (*DefaultConfigProvider) GetAPIKey

func (p *DefaultConfigProvider) GetAPIKey() (string, error)

func (*DefaultConfigProvider) LoadConfig

func (p *DefaultConfigProvider) LoadConfig() (*config.AppConfig, error)

func (*DefaultConfigProvider) LoadContext

func (p *DefaultConfigProvider) LoadContext() (string, error)
func (p *DefaultConfigProvider) LoadLinks() (*config.LinksConfig, error)

func (*DefaultConfigProvider) LoadSystemPrompt

func (p *DefaultConfigProvider) LoadSystemPrompt() (string, error)

type DefaultIssueTypeResolver

type DefaultIssueTypeResolver struct{}

DefaultIssueTypeResolver implements the IssueTypeResolver interface. Exported for tests.

func (*DefaultIssueTypeResolver) Resolve

func (r *DefaultIssueTypeResolver) Resolve(flagType string, matchedProjectLink *config.ProjectLink, projectKey string) string

type DefaultMCPClientWrapper

type DefaultMCPClientWrapper struct {
	Client *mcpclient.Client
}

DefaultMCPClientWrapper wraps the concrete mcpclient.Client to satisfy the MCPClient interface for testing. Exported for use in tests.

func (*DefaultMCPClientWrapper) CreateIssue

func (*DefaultMCPClientWrapper) SearchIssues

type DefaultProjectMapper

type DefaultProjectMapper struct{}

DefaultProjectMapper implements the ProjectMapper interface. Exported for tests.

func (*DefaultProjectMapper) MapSuggestionToKey

func (m *DefaultProjectMapper) MapSuggestionToKey(suggestion string, linksCfg *config.LinksConfig) (string, *config.ProjectLink, error)

type IssueTypeResolver

type IssueTypeResolver interface {
	Resolve(flagType string, projectLink *config.ProjectLink, defaultType string) string
}

IssueTypeResolver defines an interface for components that determine the final issue type to be used for ticket creation, considering the type provided via command flag, the default type specified in a matched ProjectLink, and a hardcoded default.

type KeyringClient

type KeyringClient interface {
	Set(service, user, password string) error
	GetAPIKey(service, user string) (string, error) // Added for config show

}

KeyringClient defines an interface for components that interact with the operating system's secure credential store (keychain/keyring). It abstracts the operations of setting and retrieving secrets, specifically the LLM API key.

type MCPClient

MCPClient defines an interface for components that communicate with the Jira MCP (Model Context Protocol) server. It abstracts the operations of creating and searching for Jira issues via the MCP API.

type MockLLMClient

type MockLLMClient struct {
	mock.Mock // Implements llm.Client
}

MockLLMClient is a mock implementation of the llm.Client interface. Exported for use in integration tests.

func (*MockLLMClient) GenerateTicketDetails

func (m *MockLLMClient) GenerateTicketDetails(ctx context.Context, userInput, systemPrompt, contextContent string) (llm.LLMResponse, error)

GenerateTicketDetails matches llm.Client interface

type ProjectMapper

type ProjectMapper interface {
	MapSuggestionToKey(suggestion string, links *config.LinksConfig) (projectKey string, matchedLink *config.ProjectLink, err error)
}

ProjectMapper defines an interface for components that can map a project name suggestion (potentially from the LLM) to a valid Jira project key using the loaded LinksConfig. It returns the mapped key and the specific ProjectLink matched.

type Provider

type Provider struct {
	Config  ConfigProvider
	MCP     MCPClient
	Keyring KeyringClient
	LLM     llm.Client // Added LLM client interface
}

Provider serves as a central dependency injection container, aggregating the various service interfaces (like ConfigProvider, MCPClient, KeyringClient) required by the application's commands. This structure simplifies passing dependencies down the call stack and facilitates mocking during testing.

func GetProvider

func GetProvider() (*Provider, error)

GetProvider is the factory function responsible for initializing and returning a fully configured Provider instance. It sets up the concrete implementations for each required service interface (e.g., defaultConfigProvider, defaultMCPClient, defaultKeyringClient). It handles loading the initial application configuration and attempts to initialize the MCP client if configured. Errors during critical initialization steps (like loading AppConfig) are returned. Warnings may be logged for non-critical failures (like MCP client init if URL is missing).

Jump to

Keyboard shortcuts

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