cmd

package
v0.5.40 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

internal/cmd/list_helper.go

Package cmd provides CLI commands for the notion-cli tool

Package cmd contains the CLI commands for notion-cli.

Index

Constants

View Source
const (
	// ProxyURL is the OAuth proxy URL
	ProxyURL = "https://notion-cli.fly.dev"
	// CallbackTimeout is how long to wait for the OAuth callback
	CallbackTimeout = 2 * time.Minute
)
View Source
const (
	MinColumnCount = 2
	MaxColumnCount = 5
)

Column layout constraints defined by the Notion API.

View Source
const (
	ExitOK        = 0
	ExitSystem    = 1
	ExitUser      = 2
	ExitAuth      = 3
	ExitNotFound  = 4
	ExitRateLimit = 5
	ExitTemp      = 6
	ExitCanceled  = 130
)
View Source
const NotionMaxPageSize = 100

NotionMaxPageSize is the maximum page size allowed by the Notion API. All paginated endpoints limit page_size to 100.

Variables

This section is empty.

Functions

func ConfigFromContext added in v0.5.9

func ConfigFromContext(ctx context.Context) *config.Config

ConfigFromContext retrieves CLI config from context.

func ErrorFormatFromContext added in v0.4.0

func ErrorFormatFromContext(ctx context.Context) string

ErrorFormatFromContext retrieves the error format from context.

func ExitCode added in v0.5.4

func ExitCode(err error) int

ExitCode maps a command error to a stable process exit code for automation.

func GetTokenFromContext

func GetTokenFromContext(ctx context.Context) (string, error)

GetTokenFromContext retrieves the token based on workspace context. If a workspace is specified in context, it gets the workspace-specific token. Otherwise, falls back to the default token retrieval.

func NewListCommand

func NewListCommand[T any](config ListConfig[T]) *cobra.Command

NewListCommand creates a Cobra command from a ListConfig.

func NewNotionClient

func NewNotionClient(ctx context.Context, token string) *notion.Client

NewNotionClient creates a new Notion API client with debug mode enabled if the --debug flag was set.

func SkillFileFromContext added in v0.5.0

func SkillFileFromContext(ctx context.Context) *skill.SkillFile

SkillFileFromContext retrieves the skill file from context

func WithConfig added in v0.5.9

func WithConfig(ctx context.Context, cfg *config.Config) context.Context

WithConfig stores loaded CLI config in context for downstream helpers.

func WithErrorFormat added in v0.4.0

func WithErrorFormat(ctx context.Context, format string) context.Context

WithErrorFormat stores the error format in the context.

func WithSearchCache added in v0.5.0

func WithSearchCache(ctx context.Context, cache *SearchCache) context.Context

WithSearchCache adds the search cache to context.

func WithSkillFile added in v0.5.0

func WithSkillFile(ctx context.Context, sf *skill.SkillFile) context.Context

WithSkillFile adds the skill file to context

func WithWorkspace

func WithWorkspace(ctx context.Context, workspace string) context.Context

WithWorkspace stores a workspace name in the context

func WorkspaceFromContext

func WorkspaceFromContext(ctx context.Context) string

WorkspaceFromContext retrieves the workspace name from the context

Types

type App added in v0.4.0

type App struct {
	Stdout    io.Writer
	Stderr    io.Writer
	Version   string
	Commit    string
	BuildTime string
}

App owns CLI wiring and execution configuration.

func NewApp added in v0.4.0

func NewApp() *App

NewApp constructs an App with default settings.

func (*App) Execute added in v0.4.0

func (a *App) Execute(ctx context.Context, args []string) error

Execute runs the CLI with the provided args.

func (*App) RootCommand added in v0.4.0

func (a *App) RootCommand() *cobra.Command

RootCommand exposes the root Cobra command for embedding/tests.

type CommandHelp added in v0.5.25

type CommandHelp struct {
	Name        string           `json:"name"`
	Aliases     []string         `json:"aliases,omitempty"`
	Short       string           `json:"short"`
	Long        string           `json:"long,omitempty"`
	Usage       string           `json:"usage"`
	Example     string           `json:"example,omitempty"`
	Flags       []FlagHelp       `json:"flags,omitempty"`
	Subcommands []SubcommandHelp `json:"subcommands,omitempty"`
}

CommandHelp represents machine-readable command documentation.

type DryRunPrinter

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

DryRunPrinter helps format dry-run output consistently across commands.

func NewDryRunPrinter

func NewDryRunPrinter(w io.Writer) *DryRunPrinter

NewDryRunPrinter creates a new DryRunPrinter that writes to the given writer.

func (*DryRunPrinter) Change

func (p *DryRunPrinter) Change(name, oldVal, newVal string)

Change prints a field that would change from one value to another. Example: Status: "In Progress" -> "Done"

func (*DryRunPrinter) Content

func (p *DryRunPrinter) Content(name, value string)

Content prints multi-line content with proper indentation. Example: Content: "This is the block content..."

func (*DryRunPrinter) Field

func (p *DryRunPrinter) Field(name, value string)

Field prints a single field with its value. Example: Type: paragraph

func (*DryRunPrinter) Footer

func (p *DryRunPrinter) Footer()

Footer prints the footer message indicating no changes were made.

func (*DryRunPrinter) Header

func (p *DryRunPrinter) Header(action, resourceType, id string)

Header prints the header line indicating the action that would be taken. Example: [DRY-RUN] Would delete block abc-123

func (*DryRunPrinter) Section

func (p *DryRunPrinter) Section(title string)

Section prints a section header. Example: Properties to update:

func (*DryRunPrinter) Unchanged

func (p *DryRunPrinter) Unchanged(name string)

Unchanged prints a field that would remain unchanged. Example: Priority: (unchanged)

type EnrichedPage added in v0.5.0

type EnrichedPage struct {
	*notion.Page
	ParentTitle string      `json:"parent_title,omitempty"`
	ChildCount  int         `json:"child_count"`
	Path        []PathEntry `json:"path,omitempty"`
}

EnrichedPage wraps a Page with additional metadata resolved via extra API calls. parent_title is the resolved title of the parent database or page. child_count is the number of immediate child blocks. path is the breadcrumb path from root to immediate parent.

type FlagHelp added in v0.5.25

type FlagHelp struct {
	Name      string `json:"name"`
	Shorthand string `json:"shorthand,omitempty"`
	Type      string `json:"type"`
	Default   string `json:"default,omitempty"`
	Usage     string `json:"usage"`
}

FlagHelp represents machine-readable flag documentation.

type ListConfig

type ListConfig[T any] struct {
	Use          string
	Short        string
	Long         string
	Example      string
	Headers      []string
	RowFunc      func(T) []string
	Fetch        func(ctx context.Context, pageSize int) (ListResult[T], error)
	EmptyMessage string
}

ListConfig configures a list command using generics.

type ListResult

type ListResult[T any] struct {
	Items   []T
	HasMore bool
}

ListResult represents a paginated list response.

type PathEntry added in v0.5.6

type PathEntry struct {
	Type  string `json:"type"` // "page" or "database"
	ID    string `json:"id"`
	Title string `json:"title,omitempty"`
}

PathEntry represents one ancestor in a page's breadcrumb path.

type ResolveCandidate added in v0.5.4

type ResolveCandidate struct {
	ID     string `json:"id"`
	Object string `json:"object"`
	Title  string `json:"title,omitempty"`
	URL    string `json:"url,omitempty"`

	Source string `json:"source,omitempty"` // "skill" or "search"
	Alias  string `json:"alias,omitempty"`
	Exact  bool   `json:"exact,omitempty"`
}

type ResolveResponse added in v0.5.4

type ResolveResponse struct {
	Object     string             `json:"object"`
	Query      string             `json:"query"`
	Filter     string             `json:"filter,omitempty"`
	Results    []ResolveCandidate `json:"results"`
	HasMore    bool               `json:"has_more"`
	NextCursor *string            `json:"next_cursor,omitempty"`
	Meta       map[string]any     `json:"_meta,omitempty"`
}

type SearchCache added in v0.5.0

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

SearchCache stores search results for the duration of a single command execution. It reduces API calls when the same search is performed multiple times (e.g., batch operations).

func NewSearchCache added in v0.5.0

func NewSearchCache() *SearchCache

NewSearchCache creates a new empty search cache.

func SearchCacheFromContext added in v0.5.0

func SearchCacheFromContext(ctx context.Context) *SearchCache

SearchCacheFromContext retrieves the search cache from context, or nil if not present.

func (*SearchCache) Get added in v0.5.0

func (c *SearchCache) Get(query, filterType string) *notion.SearchResult

Get retrieves a cached search result, returning nil if not found.

func (*SearchCache) Len added in v0.5.0

func (c *SearchCache) Len() int

Len returns the number of cached entries.

func (*SearchCache) Set added in v0.5.0

func (c *SearchCache) Set(query, filterType string, result *notion.SearchResult)

Set stores a search result in the cache.

type SubcommandHelp added in v0.5.25

type SubcommandHelp struct {
	Name    string   `json:"name"`
	Aliases []string `json:"aliases,omitempty"`
	Short   string   `json:"short"`
}

SubcommandHelp represents machine-readable subcommand documentation.

Jump to

Keyboard shortcuts

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