colon

package module
v0.0.0-...-bc5ae99 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2017 License: MIT Imports: 6 Imported by: 5

README

go-colon

Package colon for parsing colon-separated strings like PATH

Installation

$ go get github.com/b4b4r07/go-colon

Usage

Example

Set the variables as you like ^1:

export ENHANCD_FILTER="fzy:/usr/local/bin/peco --select-1:fzf --multi --ansi:zaw"

Run this script like _example.

result, err := colon.Parse(os.Getenv("ENHANCD_FILTER"))
if err != nil {
    panic(err)
}
pp.Println(result.Executable())

Result:

&colon.Result{
  colon.Object{
    Index: 1,
    Attr:  colon.Attribute{
      First: "fzy",
      Other: []string{},
      Args:  []string{
        "fzy",
      },
      Base:    "fzy",
      Dir:     "",
      IsDir:   false,
      Command: "/Users/b4b4r07/.zplug/bin/fzy",
    },
    Errors: []error{},
  },
  colon.Object{
    Index: 2,
    Attr:  colon.Attribute{
      First: "/usr/local/bin/peco",
      Other: []string{
        "--select-1",
      },
      Args: []string{
        "/usr/local/bin/peco",
        "--select-1",
      },
      Base:    "peco",
      Dir:     "/usr/local/bin",
      IsDir:   false,
      Command: "/usr/local/bin/peco",
    },
    Errors: []error{},
  },
  colon.Object{
    Index: 3,
    Attr:  colon.Attribute{
      First: "fzf",
      Other: []string{
        "--multi",
        "--ansi",
      },
      Args: []string{
        "fzf",
        "--multi",
        "--ansi",
      },
      Base:    "fzf",
      Dir:     "",
      IsDir:   false,
      Command: "/Users/b4b4r07/.zplug/bin/fzf",
    },
    Errors: []error{},
  },
}

For more info, see godoc.

License

MIT

Author

b4b4r07

Documentation

Overview

Package colon for parsing colon-separated strings like PATH

Index

Constants

This section is empty.

Variables

View Source
var (
	// Separator is an identifier for delimiting the target string
	// Defaults to os.PathListSeparator but you can change anything you want
	Separator string = string(os.PathListSeparator)

	ErrInvalid = errors.New("invalid argument")
)

Functions

This section is empty.

Types

type Parser

type Parser struct {
	Separator string
}

func NewParser

func NewParser() *Parser

NewParser creates Parser

func (*Parser) Parse

func (p *Parser) Parse(str string) (*Results, error)

Parser parses colon-separated string like PATH

type Result

type Result struct {
	// Index returns the number of the given character string
	// separated by Separator
	Index int

	Item    string
	Args    []string
	Command string

	// Errors stacks all errors that occurred during parsing
	Errors []error
}

Result is parsed result

type Results

type Results []Result

func Parse

func Parse(str string) (*Results, error)

Parse is public method exported for accessing from other package

func (*Results) Executable

func (rs *Results) Executable() *Results

Executable returns objects whose first argument is in PATH

func (*Results) Filter

func (rs *Results) Filter(fn func(Result) bool) *Results

Filter filters the parse result by condition

func (*Results) First

func (rs *Results) First() (Result, error)

func (*Results) Get

func (rs *Results) Get(args ...interface{}) *Results

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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