project

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package project holds the state of an ifc7 managed project and defines command line operations that can be performed on it.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig = fmt.Errorf("invalid config")
	ErrRefExists     = fmt.Errorf("reference already exists")
	ErrRefNotFound   = fmt.Errorf("reference not found")
	ErrNameExists    = fmt.Errorf("name already exists")
	ErrPathExists    = fmt.Errorf("path already exists")
	ErrPathRequired  = fmt.Errorf("path is required for owned interfaces")
	ErrNameRequired  = fmt.Errorf("name is required for owned interfaces")
	ErrNameNotFound  = fmt.Errorf("name not found")
)
View Source
var (
	ErrProjectExists        = fmt.Errorf("project already exists")
	ErrInvalidRef           = fmt.Errorf("invalid reference")
	ErrInvalidSpecification = fmt.Errorf("invalid interface specification")
)
View Source
var (
	ErrInvalidManifest = fmt.Errorf("invalid manifest")
)

Functions

func DetectSpecificationType

func DetectSpecificationType(data []byte) (client.InterfaceType, error)

DetectSpecificationType reports whether data is a valid OpenAPI or JSON Schema document. OpenAPI is checked first so OpenAPI documents are not classified as JSON Schema.

func FormatStatusReport

func FormatStatusReport(statuses []InterfaceStatus) string

FormatStatusReport renders a human-readable status report.

Types

type AddParams

type AddParams struct {
	Name string
	Path string
	Ref  string
}

AddParams holds parameters that can be passed to the Add method

type CheckoutParams

type CheckoutParams struct {
	// Targets are owned interface names or slugs. Empty means all owned interfaces.
	Targets []string
	// Force overwrites local files that differ from the manifest latest revision.
	Force bool
}

CheckoutParams holds parameters for Checkout.

type CommitParams

type CommitParams struct {
	Ref string
}

CommitParams holds parameters that can be passed to the Commit method

type CompareResult

type CompareResult struct {
	Before   string
	After    string
	PluginID string
	Output   contract.CompareOutput
}

CompareResult is the outcome of running a compare plugin on two specifications.

func CompareFiles

func CompareFiles(beforePath, afterPath string) (CompareResult, error)

CompareFiles runs the default change detector on two specification files.

type Config

type Config struct {
	Use []Used  `json:"use" yaml:"use"`
	Own []Owned `json:"own" yaml:"own"`
}

Config represents a project configuration file This file holds references to interfaces that are tracked by the project.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty Config struct

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads the project configuration file from disk

func (*Config) Write

func (c *Config) Write(path string) error

Write writes the project configuration file to disk

type FetchParams

type FetchParams struct {
	Ref string
}

FetchParams holds parameters that can be passed to the Fetch method

type InterfaceStatus

type InterfaceStatus struct {
	Name   string
	Slug   string
	Path   string
	Ref    string
	Kind   InterfaceStatusKind
	Detail string
}

InterfaceStatus is the working-tree status of one owned interface.

type InterfaceStatusKind

type InterfaceStatusKind string

InterfaceStatusKind describes how an owned interface compares to the local manifest.

const (
	StatusClean    InterfaceStatusKind = "clean"
	StatusModified InterfaceStatusKind = "modified"
	StatusNew      InterfaceStatusKind = "new"
	StatusMissing  InterfaceStatusKind = "missing"
	StatusError    InterfaceStatusKind = "error"
)

type LintResult

type LintResult struct {
	Target   string
	PluginID string
	Output   contract.LintOutput
}

LintResult is the outcome of running a lint plugin on a local specification.

func LintFile

func LintFile(path string) (LintResult, error)

LintFile runs the default linter for a specification file.

type Manifest

type Manifest struct {
	// Interfaces maps canonicalUrl (e.g. "/i/@user/slug") to interface data.
	// Before an interface is created on the server it may be temporarily keyed by
	// its local name (or interface ID, for legacy manifests).
	Interfaces map[string]*ManifestInterface `json:"interfaces"`
}

Manifest is the structure of the local project manifest file (manifest.json) This holds local copies and version history of all the interfaces tracked by the project.

func NewManifest

func NewManifest() *Manifest

NewManifest creates a new empty Manifest struct

func ReadManifest

func ReadManifest(path string) (*Manifest, error)

ReadManifest reads the manifest from a file

func (*Manifest) String

func (m *Manifest) String() string

String converts a manifest into string format

func (*Manifest) Write

func (m *Manifest) Write(path string) error

Write writes the manifest to a file

type ManifestInterface

type ManifestInterface struct {
	client.Interface
	Revisions map[string]*client.InterfaceRevision `json:"revisions"` // map of revision ID to revision data
	Releases  map[string]*client.InterfaceRelease  `json:"releases"`  // map of release version to release data
}

ManifestInterface holds the state of a single interface in the project manifest.

type Option

type Option func(*Project)

Option is a function that configures a Project

type Owned

type Owned struct {
	Name string `json:"name" yaml:"name"`
	Ref  string `json:"ref" yaml:"ref"`
	Path string `json:"path" yaml:"path"`
}

Owned holds a reference to a local interface that is managed by the project.

type Project

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

Project holds the state of an ifc7 managed project

func Load

func Load() (*Project, error)

Load loads a project from local files

func New

func New(opts ...Option) (*Project, error)

New instantiates a new Project struct

func (*Project) Add

func (p *Project) Add(ctx context.Context, params AddParams) error

Add adds a local interface to the project's "own" list in (ifc.yaml)

func (*Project) Checkout

func (p *Project) Checkout(ctx context.Context, params CheckoutParams) ([]string, error)

Checkout writes owned interface working-tree files from the latest revision in the local manifest. It does not contact the remote hub.

Missing files are created. Files that already match the manifest are left unchanged. Files with local modifications are skipped unless Force is set.

func (*Project) Commit

func (p *Project) Commit(ctx context.Context, params CommitParams) error

Commit adds local changes to owned interfaces to the manifest

func (*Project) DiffOwned

func (p *Project) DiffOwned(target string) (string, error)

DiffOwned returns a unified diff of an owned interface's working-tree file against the latest revision stored in the local manifest. An empty string means there are no differences. target may be an owned interface name or its manifest slug. It does not contact the remote hub.

func (*Project) Fetch

func (p *Project) Fetch(ctx context.Context, params FetchParams) error

Fetch fetches remote copies of interfaces tracked by the project

func (*Project) FindUntrackedSpecs

func (p *Project) FindUntrackedSpecs(root string) ([]ScanCandidate, error)

FindUntrackedSpecs walks root for valid OpenAPI / JSON Schema files not already tracked as owned interfaces in ifc.yaml. Returned paths are relative to the current working directory so they can be passed directly to Add.

func (*Project) Initialize

func (p *Project) Initialize() error

Initialize creates the necessary folders and files for a project if they do not exist in the current folder

func (*Project) Push

func (p *Project) Push(ctx context.Context, params PushParams) ([]string, error)

Push pushes local changes to the remote server. It returns user-facing status messages.

func (*Project) ResolveComparePath

func (p *Project) ResolveComparePath(target string) (string, error)

ResolveComparePath resolves a CLI target (owned name or file path) to a file path.

func (*Project) ResolveLintTargets

func (p *Project) ResolveLintTargets(targets []string) ([]string, error)

ResolveLintTargets resolves CLI targets to file paths. Empty targets means all owned interfaces. Named targets match owned names or file paths.

func (*Project) Scan

func (p *Project) Scan(ctx context.Context, root string) ([]string, error)

Scan recursively searches root for valid OpenAPI / JSON Schema documents that are not already listed in ifc.yaml, presents them in a TUI, and adds selected files using the same logic as Add. root defaults to the current directory.

func (*Project) Status

func (p *Project) Status(ctx context.Context) ([]InterfaceStatus, error)

Status compares each owned interface on disk against the local manifest. It does not contact the remote hub.

func (*Project) Use

func (p *Project) Use(ctx context.Context, params UseParams) error

Use adds a remote interface reference to the project's "use" list

func (*Project) Write

func (p *Project) Write() error

Write writes project files to disk

type PushParams

type PushParams struct {
	Name string
}

PushParams holds parameters that can be passed to the Push method

type ScanCandidate

type ScanCandidate struct {
	Path string
	Type client.InterfaceType
}

ScanCandidate is an untracked OpenAPI or JSON Schema file discovered by Scan.

type UseParams

type UseParams struct {
	Ref string
}

UseParams holds parameters that can be passed to the Use method

type Used

type Used struct {
	Ref string `json:"ref" yaml:"ref"`
}

Used holds a reference to a remote interface that is tracked by the project.

Jump to

Keyboard shortcuts

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