parseargs

package module
v0.0.0-...-4cb9849 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2017 License: MIT Imports: 3 Imported by: 0

README

GoDoc Codeship Codecov Go Report Card

parseargs-go

This is a port of the parserargs.js project to Go.

What about parsing arguments allowing quotes in them? But beware that this library will not parse flags (-- and -), flags will be returned as simple strings.

Installation

go get -u github.com/txgruppi/parseargs-go

Example

package main

import (
  "fmt"
  "log"

  "github.com/txgruppi/parseargs-go"
)

func main() {
  setInRedis := `set name "Put your name here"`
  parsed, err := parseargs.Parse(setInRedis)
  if err != nil {
    log.Fatal(err)
  }
  fmt.Printf("%#v\n", parsed) // []string{"set", "name", "Put your name here"}
}

Tests

go get -u -t github.com/txgruppi/parseargs-go
cd $GOPATH/src/github.com/txgruppi/parseargs-go
go test ./...

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidArgument is the error returned when an unexpected character
	// is found by the parser.
	ErrInvalidArgument = errors.New("invalid argument(s)")

	// ErrInvalidSyntax is the error returned when some of the syntax rules are
	// violeted by the input.
	ErrInvalidSyntax = errors.New("invalid syntax")

	// ErrUnexpectedEndOfInput is the error returned when the parser gets to the
	// end of the string with an unfinished string.
	ErrUnexpectedEndOfInput = errors.New("unexpected end of input")
)

Functions

func Parse

func Parse(input string) ([]string, error)

Parse parses a string into a list or arguments. The default argument separator is one or a sequence of whitespaces but it also understands quotted string and escaped quotes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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