shellutils

package
v1.13.5 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: GPL-2.0, GPL-2.0-or-later Imports: 6 Imported by: 0

README

This package contains utilities to parse user input/script input in shell-like ways, creating a parse tree, and then turn the parse tree into argument lists to execute.


© 2017 Platina Systems, Inc. All rights reserved. Use of this source code is governed by the GPL-2 license described in the LICENSE file LICENSE.

Documentation

Overview

Copyright © 2017 Platina Systems, Inc. All rights reserved. Use of this source code is governed by the GPL-2 license described in the LICENSE file.

Copyright © 2017 Platina Systems, Inc. All rights reserved. Use of this source code is governed by the GPL-2 license described in the LICENSE file.

Package shellutils provides services to parse shell-like input, produce an intermediate parse tree, and render the parse tree into string slices and a map of environment variables suitable for execution.

Index

Constants

View Source
const (
	TokenLiteral = iota
	TokenEnvget
	TokenEnvset
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmdline

type Cmdline struct {
	Cmds []Word
	Term Word
}

Cmdline is a slice of Words which may be variable setting, a command, or arguments to that command. There is a seperate terminator which is either a pipeline operator (|) or a list operator (; & || &&).

func (*Cmdline) Slice

func (c *Cmdline) Slice(getenv func(string) string) (map[string]string, []string)

Slice takes a parsed command line and returns a map of the environment variables declared in the command, and a slice of the command and its arguments as strings

type List

type List struct {
	Cmds []Cmdline
}

List is a slice of pipelines. The pipelines were concatenated via unconditional execution operators (; and &) or conditional execution operators (|| and &&).

func Parse

func Parse(prompt string, srcin func(string) (string, error)) (*List, error)

Parse calls the srcin function for command input as strings, and return a pointer to a parsed command List, or an error

type Token

type Token struct {
	V string
	T Tokentype
}

Token is a type and a string value. During parsing, we convert string input into a series of tokens.

type Tokentype

type Tokentype int

Tokentype defines the type of a token tokenLiteral is liternal string text. The string is the text of the word being assembled. tokenEnvget is a reference to an environment variable. The string is the environment variable name. Any punctuation (dollar, brace) has been stripped tokenEnvset is the operator to set an environment variable. The string is the assignment operator, i.e. =. This is represented as a token to prevent quoted = characters to be interpreted as setting environment variables

type Word

type Word struct {
	Tokens []Token
}

func (*Word) String

func (w *Word) String() string

Jump to

Keyboard shortcuts

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