Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sed ¶
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" )
Click to show internal directories.
Click to hide internal directories.