resolve

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package resolve provides interactive prompts for resolving missing CLI options. When required options like --account or --project are not specified, the resolver interactively prompts the user to select from available options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PersistAccountID

func PersistAccountID(accountID, scope string) error

PersistAccountID is a convenience function for persisting an account ID.

func PersistDefaultProfile

func PersistDefaultProfile(profileName, scope string) error

PersistDefaultProfile is a convenience function for persisting a default profile.

func PersistProjectID

func PersistProjectID(projectID, scope string) error

PersistProjectID is a convenience function for persisting a project ID.

func PersistTodolistID

func PersistTodolistID(todolistID, scope string) error

PersistTodolistID is a convenience function for persisting a todolist ID.

func PersistValue

func PersistValue(key, value, scope string) error

PersistValue saves a config value to the specified scope.

func PromptAndPersist

func PromptAndPersist(opt PersistOption) (bool, error)

PromptAndPersist asks the user if they want to save a value as default, and if so, which scope to save it in. Returns true if the value was saved.

func PromptAndPersistAccountID

func PromptAndPersistAccountID(accountID string) (bool, error)

PromptAndPersistAccountID prompts the user to save an account ID.

func PromptAndPersistDefaultProfile

func PromptAndPersistDefaultProfile(profileName string) (bool, error)

PromptAndPersistDefaultProfile prompts the user to save a default profile.

func PromptAndPersistProjectID

func PromptAndPersistProjectID(projectID string) (bool, error)

PromptAndPersistProjectID prompts the user to save a project ID.

func PromptAndPersistTodolistID

func PromptAndPersistTodolistID(todolistID string) (bool, error)

PromptAndPersistTodolistID prompts the user to save a todolist ID.

Types

type CommentTarget

type CommentTarget struct {
	RecordingID int64
	ProjectID   int64
	Type        string
	Title       string
}

CommentTarget holds the resolved target for a comment.

type CommentThread

type CommentThread struct {
	Recording *basecamp.Recording
	Comments  []basecamp.Comment
	// contains filtered or unexported fields
}

CommentThread represents a thread of comments on a recording.

func FetchCommentThread

func FetchCommentThread(ctx context.Context, r *Resolver, projectID, recordingID int64) (*CommentThread, error)

FetchCommentThread fetches and returns a comment thread for a recording.

func NewCommentThread

func NewCommentThread(recording *basecamp.Recording, comments []basecamp.Comment) *CommentThread

NewCommentThread creates a new comment thread view.

func (*CommentThread) Render

func (ct *CommentThread) Render() string

Render returns a formatted string representation of the comment thread.

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

Context is a helper type for passing context through resolution chains.

func NewContext

func NewContext(ctx context.Context, r *Resolver) *Context

NewContext creates a new resolution context.

func (*Context) Resolver

func (c *Context) Resolver() *Resolver

Resolver returns the resolver from the context.

type DockTool

type DockTool struct {
	Name    string `json:"name"`
	Title   string `json:"title"`
	ID      int64  `json:"id"`
	Enabled bool   `json:"enabled"`
}

DockTool represents a tool in a project's dock.

type DockToolResult

type DockToolResult struct {
	ToolID string
	Tool   *DockTool
	Source ResolvedSource
}

DockToolResult holds the result of dock tool resolution.

type Flags

type Flags struct {
	Account  string
	Project  string
	Todolist string

	// Machine output flags - when any of these are set, interactive prompts are disabled
	Agent   bool
	JSON    bool
	Quiet   bool
	IDsOnly bool
	Count   bool
}

Flags holds the relevant CLI flag values for resolution.

type Option

type Option func(*Resolver)

Option configures a Resolver.

func WithFlags

func WithFlags(flags *Flags) Option

WithFlags sets the CLI flags for the resolver.

func WithStyles

func WithStyles(styles *tui.Styles) Option

WithStyles sets custom TUI styles for the resolver.

type PersistOption

type PersistOption struct {
	Key   string // Config key (e.g., "account_id")
	Value string // Value to persist
	Scope string // "local" or "global"
}

PersistOption represents a config persistence option.

type ResolvedSource

type ResolvedSource int

ResolvedSource indicates where a resolved value came from.

const (
	// SourceFlag means the value came from a CLI flag.
	SourceFlag ResolvedSource = iota
	// SourceConfig means the value came from the config file.
	SourceConfig
	// SourcePrompt means the value was selected interactively.
	SourcePrompt
	// SourceDefault means a default value was used.
	SourceDefault
)

func (ResolvedSource) String

func (s ResolvedSource) String() string

String returns a human-readable description of the source.

type ResolvedValue

type ResolvedValue struct {
	Value  string
	Source ResolvedSource
}

ResolvedValue represents a value that was resolved, along with metadata about how it was resolved.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver provides interactive prompts for resolving missing CLI options. It wraps the SDK client and auth manager to fetch available options, then uses TUI components to let the user select interactively.

func New

func New(sdk *basecamp.Client, auth *auth.Manager, cfg *config.Config, opts ...Option) *Resolver

New creates a new Resolver with the given SDK client, auth manager, and config.

func (*Resolver) Account

func (r *Resolver) Account(ctx context.Context) (*ResolvedValue, error)

Account resolves the account ID using the following precedence: 1. CLI flag (--account) 2. Config file (account_id) 3. Interactive prompt (if terminal is interactive) 4. Error (if no account can be determined)

Returns the resolved account ID and the source it came from.

func (*Resolver) AccountWithPersist

func (r *Resolver) AccountWithPersist(ctx context.Context) (*ResolvedValue, error)

AccountWithPersist resolves the account ID and optionally prompts to save it. This is useful for commands that want to offer to save the selected account.

func (*Resolver) Auth

func (r *Resolver) Auth() *auth.Manager

Auth returns the auth manager for authentication operations.

func (*Resolver) Campfire

func (r *Resolver) Campfire(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

Campfire resolves a campfire ID from a project.

func (*Resolver) Comment

func (r *Resolver) Comment(ctx context.Context, onFlag string, projectID string) (*CommentTarget, error)

Comment resolves the target recording for a comment using the following precedence: 1. CLI flag (--on) 2. Interactive prompt (if terminal is interactive) 3. Error (if no target can be determined)

The project must be resolved before calling this method. Returns the resolved recording ID and project ID.

func (*Resolver) Config

func (r *Resolver) Config() *config.Config

Config returns the current config.

func (*Resolver) DockTool

func (r *Resolver) DockTool(ctx context.Context, projectID, dockName, explicitID, friendlyName string) (*DockToolResult, error)

DockTool resolves a dock tool ID from a project using the following precedence: 1. Explicit ID provided (--campfire, --board, etc.) 2. Single tool of type exists - use it automatically 3. Interactive prompt (if terminal is interactive) 4. Error listing available tools (if not interactive)

func (*Resolver) Flags

func (r *Resolver) Flags() *Flags

Flags returns the current CLI flags.

func (*Resolver) Inbox

func (r *Resolver) Inbox(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

Inbox resolves an inbox ID from a project.

func (*Resolver) IsInteractive

func (r *Resolver) IsInteractive() bool

IsInteractive returns true if interactive prompts can be shown. This checks both TTY status and machine-output flags. Returns false if any machine-output flag is set (--agent, --json, --quiet, --ids-only, --count) or if stdout is not a terminal.

func (*Resolver) MessageBoard

func (r *Resolver) MessageBoard(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

MessageBoard resolves a message board ID from a project.

func (*Resolver) Person

func (r *Resolver) Person(ctx context.Context) (*ResolvedValue, error)

Person resolves a person ID interactively. Unlike Account/Project/Todolist, Person doesn't have a config fallback since it's typically used for assignment operations where the user explicitly selects someone.

Returns the resolved person ID and the source it came from.

func (*Resolver) PersonInProject

func (r *Resolver) PersonInProject(ctx context.Context, projectID string) (*ResolvedValue, error)

PersonInProject resolves a person ID interactively from project members. This is useful when you want to limit the selection to people who have access to a specific project.

func (*Resolver) Project

func (r *Resolver) Project(ctx context.Context) (*ResolvedValue, error)

Project resolves the project ID using the following precedence: 1. CLI flag (--project) 2. Config file (project_id) 3. Interactive prompt (if terminal is interactive) 4. Error (if no project can be determined)

The account must be resolved before calling this method. Returns the resolved project ID and the source it came from.

func (*Resolver) ProjectWithPersist

func (r *Resolver) ProjectWithPersist(ctx context.Context) (*ResolvedValue, error)

ProjectWithPersist resolves the project ID and optionally prompts to save it. This is useful for commands that want to offer to save the selected project.

func (*Resolver) Questionnaire

func (r *Resolver) Questionnaire(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

Questionnaire resolves a questionnaire (Automatic Check-ins) ID from a project.

func (*Resolver) SDK

func (r *Resolver) SDK() *basecamp.Client

SDK returns the underlying SDK client for fetching data.

func (*Resolver) Schedule

func (r *Resolver) Schedule(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

Schedule resolves a schedule ID from a project.

func (*Resolver) Styles

func (r *Resolver) Styles() *tui.Styles

Styles returns the TUI styles.

func (*Resolver) Todolist

func (r *Resolver) Todolist(ctx context.Context, projectID string) (*ResolvedValue, error)

Todolist resolves the todolist ID using the following precedence: 1. CLI flag (--todolist) 2. Config file (todolist_id) 3. Auto-select if exactly one todolist exists (non-interactive fallback) 4. Interactive prompt (if terminal is interactive) 5. Error (if no todolist can be determined)

The project must be resolved before calling this method. Returns the resolved todolist ID and the source it came from.

func (*Resolver) TodolistWithPersist

func (r *Resolver) TodolistWithPersist(ctx context.Context, projectID string) (*ResolvedValue, error)

TodolistWithPersist resolves the todolist ID and optionally prompts to save it.

func (*Resolver) Todoset

func (r *Resolver) Todoset(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

Todoset resolves a todoset ID from a project.

func (*Resolver) Vault

func (r *Resolver) Vault(ctx context.Context, projectID, explicitID string) (*DockToolResult, error)

Vault resolves a vault (Docs & Files) ID from a project.

Jump to

Keyboard shortcuts

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