Documentation ¶
Overview ¶
Package replace provides a text replacement Worker concept for iteratively and selectively working with searching and replacing content.
Index ¶
- Constants
- Variables
- type Iterator
- func (i *Iterator) ApplyAll() (count int, unified, backup string, err error)
- func (i *Iterator) ApplySpecific(delta *diff.Diff) (count int, unified, backup string, err error)
- func (i *Iterator) Name() (path string)
- func (i *Iterator) Next()
- func (i *Iterator) Pos() (pos int)
- func (i *Iterator) Replace() (original, modified string, count int, delta *diff.Diff, err error)
- func (i *Iterator) Valid() (valid bool)
- type Worker
- func (w *Worker) FileWriterErr() (fwe filewriter.FileWriter)
- func (w *Worker) FileWriterOut() (fwo filewriter.FileWriter)
- func (w *Worker) FindMatching(fn rpl.FindAllMatchingFn) (err error)
- func (w *Worker) Init() (err error)
- func (w *Worker) InitTargets() (err error)
- func (w *Worker) StartIterating() (iter *Iterator)
- func (w *Worker) String() (s string)
Constants ¶
View Source
const ( CaseSensitivityCategory = "1. Case Sensitivity" RegularExpressionsCategory = "2. Regular Expressions" UserInterfaceCategory = "3. User Interface" BackupsCategory = "4. Backups" TargetSelectionCategory = "5. Target Selection" GeneralCategory = "6. General" GoCursesCategory = "7. Go-Curses" )
Variables ¶
View Source
var ( BackupFlag = &cli.BoolFlag{Category: BackupsCategory, Name: "backup", Aliases: []string{"b"}, Usage: "make backups before replacing content", } BackupExtensionFlag = &cli.StringFlag{Category: BackupsCategory, Name: "backup-extension", Aliases: []string{"B"}, Usage: "specify the backup file suffix to use (implies -b)", } IgnoreCaseFlag = &cli.BoolFlag{Category: CaseSensitivityCategory, Name: "ignore-case", Aliases: []string{"i"}, Usage: "perform a case-insensitive search (plain or regex)", } PreserveCaseFlag = &cli.BoolFlag{Category: CaseSensitivityCategory, Name: "preserve-case", Aliases: []string{"P"}, Usage: "try to preserve replacement string cases", } NoLimitsFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "no-limits", Aliases: []string{"U"}, Usage: "ignore max file count and size limits", } NopFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "nope", Aliases: []string{"nop", "n"}, Usage: "report what would otherwise have been done", } ShowDiffFlag = &cli.BoolFlag{Category: UserInterfaceCategory, Name: "show-diff", Aliases: []string{"d"}, Usage: "output unified diffs for all changes", } InteractiveFlag = &cli.BoolFlag{Category: UserInterfaceCategory, Name: "interactive", Aliases: []string{"e"}, Usage: "selectively apply changes per-file", } PauseFlag = &cli.BoolFlag{Category: UserInterfaceCategory, Name: "pause", Aliases: []string{"E"}, Usage: "pause on file search results screen (implies -e)", } RecurseFlag = &cli.BoolFlag{Category: TargetSelectionCategory, Name: "recurse", Aliases: []string{"R"}, Usage: "travel directory paths", } AllFlag = &cli.BoolFlag{Category: TargetSelectionCategory, Name: "all", Aliases: []string{"a"}, Usage: "include backups and files that start with a dot", } NullFlag = &cli.BoolFlag{Category: TargetSelectionCategory, Name: "null", Aliases: []string{"0"}, Usage: "read null-terminated paths from os.Stdin", } FileFlag = &cli.StringSliceFlag{Category: TargetSelectionCategory, Name: "file", Aliases: []string{"f"}, Usage: "read paths listed in files", } ExcludeFlag = &cli.StringSliceFlag{Category: TargetSelectionCategory, Name: "exclude", Aliases: []string{"X"}, Usage: "exclude files matching glob pattern", } IncludeFlag = &cli.StringSliceFlag{Category: TargetSelectionCategory, Name: "include", Aliases: []string{"I"}, Usage: "include on files matching glob pattern", } RegexFlag = &cli.BoolFlag{Category: RegularExpressionsCategory, Name: "regex", Aliases: []string{"r"}, Usage: "search and replace arguments are regular expressions", } MultiLineFlag = &cli.BoolFlag{Category: RegularExpressionsCategory, Name: "multi-line", Aliases: []string{"m"}, Usage: "set the multiline (?m) global flag (implies -r)", } DotMatchNlFlag = &cli.BoolFlag{Category: RegularExpressionsCategory, Name: "dot-match-nl", Aliases: []string{"s"}, Usage: "set the dot-match-nl (?s) global flag (implies -r)", } QuietFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "quiet", Aliases: []string{"q"}, Usage: "silence notices", } VerboseFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "verbose", Aliases: []string{"v"}, Usage: "verbose notices", } UsageFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "usage", Aliases: []string{"h"}, Usage: "display command-line usage information", } HelpFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "help", Usage: "display complete command-line help text", } VersionFlag = &cli.BoolFlag{Category: GeneralCategory, Name: "version", Aliases: []string{"V"}, Usage: "display the version", } )
View Source
var ( DefaultBackupExtension = "~" DefaultBackupSeparator = "~" )
View Source
var ( TempErrPattern = fmt.Sprintf("rpl-%d.*.err", os.Getpid()) TempOutPattern = fmt.Sprintf("rpl-%d.*.out", os.Getpid()) )
View Source
var ( ErrNotFound = errors.New("not found") ErrTooManyFiles = fmt.Errorf("%w; try batches of %d or less", rpl.ErrTooManyFiles, rpl.MaxFileCount) )
View Source
var (
MaxFileSizeLabel = humanize.Bytes(uint64(rpl.MaxFileSize))
)
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
func (*Iterator) ApplySpecific ¶
type Worker ¶
type Worker struct { Regex bool MultiLine bool DotMatchNl bool Recurse bool Nop bool All bool IgnoreCase bool PreserveCase bool BinAsText bool RelativePath string Backup bool BackupExtension string NoLimits bool ShowDiff bool Interactive bool Pause bool Quiet bool Verbose bool Argv []string Argc int Search string Pattern *regexp.Regexp Replace string Stdin bool Null bool AddFile []string Include globs.Globs IncludeArgs []string Exclude globs.Globs ExcludeArgs []string Paths []string Targets []string Files []string Matched []string Notifier notify.Notifier // contains filtered or unexported fields }
func MakeWorker ¶
func (*Worker) FileWriterErr ¶
func (w *Worker) FileWriterErr() (fwe filewriter.FileWriter)
func (*Worker) FileWriterOut ¶
func (w *Worker) FileWriterOut() (fwo filewriter.FileWriter)
func (*Worker) FindMatching ¶
func (w *Worker) FindMatching(fn rpl.FindAllMatchingFn) (err error)
func (*Worker) InitTargets ¶
func (*Worker) StartIterating ¶
Click to show internal directories.
Click to hide internal directories.