command

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 4 Imported by: 0

README

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sed

func Sed(script SedScript) gloo.Command[[]byte, []byte]

Sed returns a command that applies a single GNU-style s/// substitution to each input line.

Supported script form: s<delim>pattern<delim>replacement<delim>flags Any single byte may be the delimiter (e.g. s|old|new|). Supported flags:

  • g — global: replace every match on the line.
  • i — ignore case.
  • p — print: emit the line again when a substitution occurred.
  • N — a decimal number: replace only the Nth match.

An invalid script makes the command fail on its first line so the error surfaces through the pipeline.

Example
package main

import (
	"fmt"

	"github.com/gloo-foo/testable"

	command "github.com/gloo-foo/cmd-sed"
)

func main() {
	lines, _ := testable.TestLines(command.Sed("s/hello/world/"), "hello foo\nhello bar\n")
	for _, line := range lines {
		fmt.Println(line)
	}
}
Output:
world foo
world bar
Example (Global)
package main

import (
	"fmt"

	"github.com/gloo-foo/testable"

	command "github.com/gloo-foo/cmd-sed"
)

func main() {
	lines, _ := testable.TestLines(command.Sed("s/a/x/g"), "banana\n")
	for _, line := range lines {
		fmt.Println(line)
	}
}
Output:
bxnxnx

Types

type Error

type Error string

Error is the sentinel error type for every failure this package can emit. Comparing with errors.Is against the constants below is the supported test.

const (
	// ErrUnsupportedExpression is returned when the script is not an s/// command.
	ErrUnsupportedExpression Error = "sed: unsupported expression"
	// ErrIncompleteSubstitution is returned when the s/// form lacks its parts.
	ErrIncompleteSubstitution Error = "sed: incomplete substitution"
	// ErrInvalidPattern is returned when the regular expression does not compile.
	ErrInvalidPattern Error = "sed: invalid pattern"
	// ErrInvalidFlags is returned when the trailing flag string is not understood.
	ErrInvalidFlags Error = "sed: invalid flags"
)

func (Error) Error

func (e Error) Error() string

type SedScript

type SedScript string

SedScript is a GNU-style substitution script of the form s<delim>pattern<delim>replacement<delim>flags, e.g. "s/old/new/g".

Directories

Path Synopsis
Package alias provides an unprefixed name for the sed command.
Package alias provides an unprefixed name for the sed command.

Jump to

Keyboard shortcuts

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