Documentation
¶
Index ¶
- Variables
- func GetPackageNameFromSectionHeader(tokens []string) string
- func ParsePatchTagNumber(tag string) (int, bool)
- func StructuralParsePatchTagNumber(tag string) (int, bool)
- type Context
- type EditorMode
- type Line
- type OpenOption
- type ParsedLine
- type ParsedLineType
- type RawLine
- type SectionStartLine
- type SectionTarget
- type SectionType
- type Spec
- func (s *Spec) AddChangelogEntry(user, email, version, release string, at time.Time, details []string) error
- func (s *Spec) AddPatchEntry(pkg, filename string) error
- func (s *Spec) AddTag(pkg, tag, value string) error
- func (s *Spec) AppendLines(lines []string)
- func (s *Spec) AppendLinesToSection(section, pkg string, lines []string) error
- func (s *Spec) GetHighestPatchTagNumber() (int, error)
- func (s *Spec) GetLastTag(pkg, tag string) (string, error)
- func (s *Spec) GetTag(pkg, tag string) (string, error)
- func (s *Spec) HasSection(section string) (bool, error)
- func (s *Spec) InsertLinesAt(lines []string, lineNumber int)
- func (s *Spec) InsertTag(pkg, tag, value string) error
- func (s *Spec) PrependLines(lines []string)
- func (s *Spec) PrependLinesToSection(section, pkg string, lines []string) error
- func (s *Spec) RemoveLine(lineNumber int)
- func (s *Spec) RemoveLines(start, end int)
- func (s *Spec) RemovePatchEntry(pattern string) error
- func (s *Spec) RemoveSection(section, pkg string) error
- func (s *Spec) RemoveSubpackage(pkg string) error
- func (s *Spec) RemoveTag(pkg, tag, value string) error
- func (s *Spec) RemoveTagsMatching(pkg string, matcher func(string, string) bool) (int, error)
- func (s *Spec) ReplaceLine(lineNumber int, replacement string)
- func (s *Spec) SearchAndReplace(section, pkg, regex, replacement string) error
- func (s *Spec) Serialize(writer io.Writer) error
- func (s *Spec) SetTag(pkg, tag, value string) error
- func (s *Spec) UpdateExistingTag(pkg, tag, value string) error
- func (s *Spec) Visit(visitor Visitor) error
- func (s *Spec) VisitTags(visitor func(tagLine *TagLine, ctx *Context) error) error
- func (s *Spec) VisitTagsPackage(packageName string, visitor func(tagLine *TagLine, ctx *Context) error) error
- type TagLine
- type VisitTarget
- type VisitTargetType
- type Visitor
Constants ¶
This section is empty.
Variables ¶
var ErrConditionalSpansSections = errors.New("conditional block spans across section boundaries")
ErrConditionalSpansSections is returned when a conditional block (%if/%endif) spans across section boundaries, making it impossible to safely remove the section without breaking the conditional nesting structure.
var ErrNoSuchTag = errors.New("no such tag")
ErrNoSuchTag is returned when a requested tag does not exist in the spec.
var ErrPatternNotFound = errors.New("pattern not found")
ErrPatternNotFound is returned when a search pattern does not match any content in the spec.
var ErrSectionNotFound = errors.New("section not found")
ErrSectionNotFound is returned when a requested section does not exist in the spec.
Functions ¶
func GetPackageNameFromSectionHeader ¶
GetPackageNameFromSectionHeader extracts the package name from the tokens of a section header line. For example, for a line like "%package -n foo", it would return "foo". For a line like "%package foo", it would return "foo" as well. Because this function does not know the base name of the spec, it cannot take a suffix-only name and resolve it to a full name.
func ParsePatchTagNumber ¶
ParsePatchTagNumber checks if the given tag name is a PatchN tag (case-insensitive) and returns the numeric suffix N. Returns -1, false if the tag is not a PatchN tag or the suffix is not a valid integer.
func StructuralParsePatchTagNumber ¶ added in v1.1.0
StructuralParsePatchTagNumber checks if the given tag name is a PatchN tag (case-insensitive) and returns the numeric suffix N. Returns -1, false if the tag is not a PatchN tag or the suffix is not a valid integer.
Types ¶
type Context ¶
type Context struct {
// Target is the current visit target.
Target VisitTarget
// RawLine is the raw text of the current line, if applicable (nil otherwise).
RawLine *string
// CurrentSection is the current section being visited.
CurrentSection SectionTarget
// CurrentLineNum is the current (0-indexed) line number being visited.
CurrentLineNum int
// contains filtered or unexported fields
}
Context provides context information to a visitor function when visiting a spec.
func (*Context) InsertLinesAfter ¶
InsertLinesAfter inserts the provided lines just after the line currently being visited, updating the context accordingly. The next line to be visited will be the line following the newly inserted lines.
func (*Context) InsertLinesBefore ¶
InsertLinesBefore inserts the provided lines just before the line currently being visited, updating the context accordingly. The next line to be visited will be the line following the current one being visited.
func (*Context) RemoveLine ¶
func (ctx *Context) RemoveLine()
RemoveLine removes the line currently being visited, updating the context accordingly. The next line to be visited will be the line that followed the removed line.
func (*Context) ReplaceLine ¶
ReplaceLine replaces the line currently being visited with the provided replacement line, updating the context accordingly.
type EditorMode ¶ added in v1.1.0
type EditorMode string
EditorMode identifies the implementation that edits an RPM spec.
const ( // EditorLegacy uses the established line-oriented editor. EditorLegacy EditorMode = "legacy" // EditorStructural uses the lossless structural editor. EditorStructural EditorMode = "structural" )
type Line ¶
type Line struct {
// Text is the original physical text of the line.
Text string
// Parsed is the parsed representation of the line's contents.
Parsed ParsedLine
}
Line represents a single line in an RPM spec file.
type OpenOption ¶ added in v1.1.0
type OpenOption func(*editorOptions)
OpenOption configures OpenSpec.
func WithEditor ¶ added in v1.1.0
func WithEditor(mode EditorMode) OpenOption
WithEditor selects the editor implementation used by OpenSpec.
type ParsedLine ¶
type ParsedLine interface {
// GetType returns the type of the parsed line.
GetType() ParsedLineType
}
ParsedLine is the interface that all parsed line types implement.
type ParsedLineType ¶
type ParsedLineType string
ParsedLineType represents the type of a parsed line.
const ( // SectionStart applies to lines that start a new section, e.g. "%description". SectionStart ParsedLineType = "SectionStart" // Tag applies to lines that define a tag, e.g. "Name: foo". Tag ParsedLineType = "Tag" // Raw applies to lines that are raw text, e.g. a line in a script section. Raw ParsedLineType = "Raw" )
type RawLine ¶
type RawLine struct {
// Content is the raw line text.
Content string
}
RawLine represents a line that is raw text.
func (*RawLine) GetType ¶
func (*RawLine) GetType() ParsedLineType
GetType returns the type of the parsed line.
type SectionStartLine ¶
type SectionStartLine struct {
SectType SectionType
SectName string
Tokens []string
}
SectionStartLine represents a line that starts a new section in the spec, e.g.: "%build".
func (*SectionStartLine) GetType ¶
func (*SectionStartLine) GetType() ParsedLineType
GetType returns the type of the parsed line.
type SectionTarget ¶
type SectionTarget struct {
// SectName is the name of the section, e.g. "%description".
SectName string
// SectType is the type of the section.
SectType SectionType
// Package is the package this section applies to, if any. Left empty for
// the default package or sections that aren't package-specific.
Package string
}
SectionTarget encapsulates information about the current section context.
type SectionType ¶
type SectionType string
SectionType represents the type of a section in an RPM spec file.
const ( // PackageSection applies to sections that define a package, e.g. "%package -n foo". PackageSection SectionType = "Package" // ScriptSection applies to sections that contain scripts, e.g. "%build". ScriptSection SectionType = "Script" // RawSection applies to sections that contain raw content, e.g.: "%description". RawSection SectionType = "Raw" // ChangelogSection applies to the "%changelog" section. ChangelogSection SectionType = "Changelog" // FilesSection applies to a "%files" section. FilesSection SectionType = "Files" // SourceFileListSection applies to a section that lists source files, e.g.: "%sourcelist". SourceFileListSection SectionType = "SourceFileList" )
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec is the public facade for a configuration-selected RPM spec editor.
func OpenSpec ¶
func OpenSpec(reader io.Reader, options ...OpenOption) (*Spec, error)
OpenSpec reads a spec and selects its editor once. With no option, it preserves the established legacy behavior.
func (*Spec) AddChangelogEntry ¶
func (s *Spec) AddChangelogEntry(user, email, version, release string, at time.Time, details []string) error
AddChangelogEntry adds an entry to the changelog section.
func (*Spec) AddPatchEntry ¶
AddPatchEntry registers a patch in the spec.
func (*Spec) AppendLines ¶ added in v0.2.0
AppendLines adds lines at the end of the spec.
func (*Spec) AppendLinesToSection ¶
AppendLinesToSection adds lines at the end of a section.
func (*Spec) GetHighestPatchTagNumber ¶
GetHighestPatchTagNumber returns the highest PatchN tag number.
func (*Spec) GetLastTag ¶ added in v1.1.0
GetLastTag returns the final matching tag in the specified package.
func (*Spec) GetTag ¶ added in v1.1.0
GetTag returns the first matching tag in the specified package.
func (*Spec) HasSection ¶
HasSection reports whether a section exists.
func (*Spec) InsertLinesAt ¶
InsertLinesAt inserts lines before the specified 0-indexed line number.
func (*Spec) PrependLines ¶ added in v0.2.0
PrependLines adds lines at the start of the spec.
func (*Spec) PrependLinesToSection ¶
PrependLinesToSection adds lines at the start of a section.
func (*Spec) RemoveLine ¶
RemoveLine removes the line at the specified 0-indexed line number.
func (*Spec) RemoveLines ¶ added in v0.2.0
RemoveLines removes the lines in the specified 0-indexed range.
func (*Spec) RemovePatchEntry ¶
RemovePatchEntry removes patch references matching pattern.
func (*Spec) RemoveSection ¶ added in v0.2.0
RemoveSection removes a section from the specified package.
func (*Spec) RemoveSubpackage ¶ added in v0.2.0
RemoveSubpackage removes all sections for a sub-package.
func (*Spec) RemoveTagsMatching ¶
RemoveTagsMatching removes tags matched by matcher from the specified package.
func (*Spec) ReplaceLine ¶
ReplaceLine replaces the line at the specified 0-indexed line number.
func (*Spec) SearchAndReplace ¶
SearchAndReplace replaces matching content in a section.
func (*Spec) UpdateExistingTag ¶
UpdateExistingTag updates every matching tag in the specified package.
func (*Spec) VisitTags ¶
VisitTags iterates over all tag lines across all packages, calling the visitor function for each one. The visitor receives the parsed TagLine and the mutation Context.
func (*Spec) VisitTagsPackage ¶ added in v0.2.0
func (s *Spec) VisitTagsPackage(packageName string, visitor func(tagLine *TagLine, ctx *Context) error) error
VisitTagsPackage iterates over all tag lines in the given package, calling the visitor function for each one. The visitor receives the parsed TagLine and the mutation Context.
type TagLine ¶
type TagLine struct {
// Tag is the name of the tag being defined.
Tag string
// Value is the value assigned to the tag.
Value string
}
TagLine encapsulates the definition of a tag.
func (*TagLine) GetType ¶
func (*TagLine) GetType() ParsedLineType
GetType returns the type of the parsed line.
type VisitTarget ¶
type VisitTarget struct {
// TargetType is the type of the current visit target.
TargetType VisitTargetType
// Optionally, provides more detail about the target's section.
// Left nil when the target is not part of a section.
Section *SectionTarget
// Optionally, provides more detail about the target's line. Left nil
// when the target is not a line.
Line *Line
}
VisitTarget encapsulates the current target of a visit operation.
type VisitTargetType ¶
type VisitTargetType string
VisitTargetType indicates the type of a visit target.
const ( // SpecStartTarget indicates the start of the spec. SpecStartTarget VisitTargetType = "SpecStart" // SectionStartTarget indicates the start of a section. SectionStartTarget VisitTargetType = "SectionStart" // SectionLineTarget indicates a line within a section. SectionLineTarget VisitTargetType = "SectionLine" // SectionEndTarget indicates the end of a section. SectionEndTarget VisitTargetType = "SectionEnd" // SpecEndTarget indicates the end of the spec. SpecEndTarget VisitTargetType = "SpecEnd" )
type Visitor ¶
Visitor is the type of a visitor function that can be passed to Spec.Visit.