command

package module
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 3 Imported by: 0

README

Documentation

Index

Examples

Constants

View Source
const (
	TrDelete   trDeleteFlag = true
	TrNoDelete trDeleteFlag = false
)
View Source
const (
	TrSqueeze   trSqueezeFlag = true
	TrNoSqueeze trSqueezeFlag = false
)
View Source
const (
	TrComplement   trComplementFlag = true
	TrNoComplement trComplementFlag = false
)

Variables

This section is empty.

Functions

func Tr

func Tr(from, to TrSet, opts ...any) gloo.Command[[]byte, []byte]

Tr returns a Command that translates, deletes, or squeezes characters. from is the source character set (set1), to is the replacement character set (set2). Character ranges like "a-z" are expanded automatically.

Flags:

  • TrDelete (-d): delete characters in set1
  • TrSqueeze (-s): squeeze repeated characters
  • TrComplement (-c): operate on the complement of set1
Example
package main

import (
	"fmt"

	"github.com/gloo-foo/testable"

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

func main() {
	lines, _ := testable.TestLines(
		command.Tr("a-z", "A-Z"),
		"hello world\n",
	)
	for _, line := range lines {
		fmt.Println(line)
	}
}
Output:
HELLO WORLD
Example (Delete)
package main

import (
	"fmt"

	"github.com/gloo-foo/testable"

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

func main() {
	lines, _ := testable.TestLines(
		command.Tr("aeiou", "", command.TrDelete),
		"hello world\n",
	)
	for _, line := range lines {
		fmt.Println(line)
	}
}
Output:
hll wrld
Example (Squeeze)
package main

import (
	"fmt"

	"github.com/gloo-foo/testable"

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

func main() {
	lines, _ := testable.TestLines(
		command.Tr(" ", "", command.TrSqueeze),
		"hello   world\n",
	)
	for _, line := range lines {
		fmt.Println(line)
	}
}
Output:
hello world

Types

type TrSet

type TrSet string

TrSet is a tr character set argument (SET1 or SET2). Character ranges like "a-z" are expanded by the command before use.

Directories

Path Synopsis
Package alias provides short names for tr command flags.
Package alias provides short names for tr command flags.

Jump to

Keyboard shortcuts

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