rpath

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 13 Imported by: 0

README

rpath

❯ ./dist/rpath --help
rpath - find path of the element present at specified position

Usage:

  rpath [flags] CATEGORY [FILE]

Available CATEGORY:
- yaml, yml
- json

Flags:
  -column int
        Column number of target, 1-based
  -debug
        Enable debug logs
  -line int
        Line number of target, 1-based
  -offset int
        Offset of target, 0-based (default -1)
  -verbose
        Verbose output

Examples

❯ cat - <<EOS | rpath -line 6 -column 10 yaml
apiVersion: v1
kind: Text
metadata:
  name: sometext
spec:
  text1: テキスト
  text2: text
EOS
$.spec.text1
❯ cat - <<EOS | rpath -line 8 -column 14 json
{
  "apiVersion": "v1",
  "kind": "Text",
  "metadata": {
    "name": "sometext"
  },
  "spec": {
    "text1": "テキスト",
    "text2": "text"
  }
}
EOS
.["spec"]["text1"]

Tasks

all

Requires: lint, test, build

test

Run unit tests and e2e tests.

go test -v -cover -race ./...

build

Build executable binary to dist/rpath.

./xc buildx "" ""

buildx

Build executable binary to dist/rpath.

Inputs: os, arch

goos=${os:-$(go env GOOS)}
goarch=${arch:-$(go env GOARCH)}
GOOS="$goos" GOARCH="$goarch" go build -trimpath -v -o dist/rpath ./cmd/rpath

lint

Run linters.

Requires: vet, vuln

vet

Examine code.

go vet ./...

vuln

Find vulnerabilities.

go tool govulncheck ./...

docker

Requires: docker-lint, docker-test, docker-build

docker-build

Build executable binary to dist/rpath.

export os="$(go env GOOS)"
export arch="$(go env GOARCH)"
./xc docker-buildx

docker-buildx

Build executable binary to dist/rpath.

Inputs: os, arch

docker build --progress plain --target build --build-arg os=$os --build-arg arch=$arch -o dist .

docker-test

Run unit tests and e2e tests.

docker build --progress plain --target test .

docker-lint

Run linters.

Requires: docker-vet, docker-vuln

docker-vet

Examine code.

docker build --progress plain --target vet .

docker-vuln

Find vulnerabilities.

docker build --progress plain --target vuln .

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("NotFound")
)

Functions

func EnableDebug

func EnableDebug()

func FindClosestCeiling

func FindClosestCeiling[S ~[]E, E, T any](
	xs S,
	target T,
	cmp func(E, T) int,
) (int, bool)

FindClosestCeiling finds the smallest element of xs not less than target.

xs must be sorted in increasing order, defined by cmp. if cmp(a, b) < 0 then value of a < b and cmp(a, b) >= 0 then value of a >= b.

func FindClosestFloor

func FindClosestFloor[S ~[]E, E, T any](
	xs S,
	target T,
	cmp func(E, T) int,
) (int, bool)

FindClosestFloor finds the largest element of xs not exceeding target.

xs must be sorted in increasing order, defined by cmp. if cmp(a, b) < 0 then value of a < b and cmp(a, b) >= 0 then value of a >= b.

func OnDebug

func OnDebug(f func())

Types

type ItemNode

type ItemNode interface {
	Node
	// Path except index.
	ItemPath() string
	ItemIndex() int
}

type JSONItemNode

type JSONItemNode struct {
	JSONNode
	// contains filtered or unexported fields
}

func (JSONItemNode) ItemIndex

func (n JSONItemNode) ItemIndex() int

func (JSONItemNode) ItemPath

func (n JSONItemNode) ItemPath() string

type JSONNode

type JSONNode struct {
	// contains filtered or unexported fields
}

func NewJSONNode

func NewJSONNode(node jsonast.JNode) *JSONNode

func (JSONNode) AsItemNode

func (n JSONNode) AsItemNode() (*JSONItemNode, bool)

func (JSONNode) Clone

func (n JSONNode) Clone() Node

func (JSONNode) Describe

func (n JSONNode) Describe() string

func (JSONNode) Meta

func (n JSONNode) Meta() any

func (JSONNode) Path

func (n JSONNode) Path() string

func (JSONNode) Pos

func (n JSONNode) Pos() *Position

type JSONQuery

type JSONQuery struct{}

func (*JSONQuery) Query

func (q *JSONQuery) Query(r io.Reader, p *Position) (*Result, error)

type Node

type Node interface {
	// Pos is the starting position of the node.
	Pos() *Position
	Path() string
	Describe() string
	Meta() any
	Clone() Node
}

type PathNodeComplementor

type PathNodeComplementor struct {
	// contains filtered or unexported fields
}

func NewPathNodeComplementor

func NewPathNodeComplementor(nodeMap *PathNodeMap) *PathNodeComplementor

func (PathNodeComplementor) Complement

func (c PathNodeComplementor) Complement() []Node

Complement generates missing nodes to find nodes by offset.

type PathNodeMap

type PathNodeMap struct {
	// contains filtered or unexported fields
}

Path to Node list map.

func NewPathNodeMap

func NewPathNodeMap() *PathNodeMap

func (*PathNodeMap) Add

func (m *PathNodeMap) Add(node Node)

func (*PathNodeMap) Find

func (m *PathNodeMap) Find(offset int) (*PathNodePair, bool)

Find finds node containing offset.

If multiple nodes are found, returns the one with the smaller range.

func (PathNodeMap) SortedNodes

func (m PathNodeMap) SortedNodes() []Node

type PathNodeMapEntry

type PathNodeMapEntry struct {
	Nodes []Node
}

func (PathNodeMapEntry) In

func (e PathNodeMapEntry) In(offset int) bool

func (PathNodeMapEntry) IsValid

func (e PathNodeMapEntry) IsValid() bool

func (PathNodeMapEntry) Size

func (e PathNodeMapEntry) Size() int

type PathNodePair

type PathNodePair struct {
	Left  Node
	Right Node
}

func (PathNodePair) GetMeta

func (p PathNodePair) GetMeta(content []byte) map[string]any

type Position

type Position struct {
	// Line number, 1-based.
	Line int `json:"line"`
	// Column number, 1-based.
	Column int `json:"column"`
	// Offset of document, 0-based.
	Offset int `json:"offset"`
}

func NewFirstPosition

func NewFirstPosition() *Position

func NewLastPosition

func NewLastPosition(bytes ybase.Bytes) *Position

func (Position) Clone

func (p Position) Clone() *Position

func (*Position) Fill

func (p *Position) Fill(b ybase.Bytes) error

type Queryer

type Queryer interface {
	// Query finds the path of the element present at specified position.
	Query(r io.Reader, p *Position) (*Result, error)
}

type Result

type Result struct {
	Position *Position `json:"pos"`
	Path     string    `json:"path"`
	Left     any       `json:"left"`
	Right    any       `json:"right"`
	Meta     any       `json:"meta"`
}

type YAMLItemNode

type YAMLItemNode struct {
	YAMLNode
	// contains filtered or unexported fields
}

func (YAMLItemNode) Describe

func (n YAMLItemNode) Describe() string

func (YAMLItemNode) ItemIndex

func (n YAMLItemNode) ItemIndex() int

func (YAMLItemNode) ItemPath

func (n YAMLItemNode) ItemPath() string

type YAMLNode

type YAMLNode struct {
	// contains filtered or unexported fields
}

func NewYAMLNode

func NewYAMLNode(node ast.Node, bytes ybase.Bytes) (*YAMLNode, bool)

func (YAMLNode) AsItemNode

func (n YAMLNode) AsItemNode() (*YAMLItemNode, bool)

func (YAMLNode) Clone

func (n YAMLNode) Clone() Node

func (YAMLNode) Describe

func (n YAMLNode) Describe() string

func (YAMLNode) Meta

func (n YAMLNode) Meta() any

func (YAMLNode) Path

func (n YAMLNode) Path() string

func (YAMLNode) Pos

func (n YAMLNode) Pos() *Position

type YamlQuery

type YamlQuery struct{}

YamlQuery finds yaml path of the element present at specified position.

func (*YamlQuery) Query

func (q *YamlQuery) Query(r io.Reader, p *Position) (*Result, error)

Directories

Path Synopsis
cmd
rpath command

Jump to

Keyboard shortcuts

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