parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package parser package help parse various strings into meaningful - bash commands or chains of bash commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPackageUpdateCommand

func HasPackageUpdateCommand(packageManager string, bashCommand BashCommand) bool

func IsApkPackageInstall

func IsApkPackageInstall(bashCommand BashCommand) bool

func IsApkPackageManager

func IsApkPackageManager(bin string) bool

func IsArchPackageManager

func IsArchPackageManager(bin string) bool

func IsDebPackageInstall

func IsDebPackageInstall(bashCommand BashCommand) bool

func IsDebPackageManager

func IsDebPackageManager(bin string) bool

func IsDnfPackageManager

func IsDnfPackageManager(bin string) bool

func IsFedoraPackageInstall

func IsFedoraPackageInstall(bashCommand BashCommand) bool

func IsNpmPackageInstall

func IsNpmPackageInstall(bashCommand BashCommand) bool

func IsNpmPackageManager

func IsNpmPackageManager(bin string) bool

func IsPythonPackageInstall

func IsPythonPackageInstall(bashCommand BashCommand) bool

func IsPythonPackageManager

func IsPythonPackageManager(bin string) bool

func IsRpmPackageInstall

func IsRpmPackageInstall(bashCommand BashCommand) bool

func IsRpmPackageManager

func IsRpmPackageManager(bin string) bool

func IsRubyPackageInstall

func IsRubyPackageInstall(bashCommand BashCommand) bool

func IsRubyPackageManager

func IsRubyPackageManager(bin string) bool

func IsSusePackageInstall

func IsSusePackageInstall(bashCommand BashCommand) bool

func IsZyppPackageManager

func IsZyppPackageManager(bin string) bool

func SplitBashChainLex

func SplitBashChainLex(strList []string) ([][]string, []string)

splitBashChainLex splits a bash command lex chain on a set of delimiters. It returns the list of bash commands lexes in the chain and the delimiters between them.

Types

type BashCommand

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

BashCommand represents a single bash command in a semantically mostly parsed form. It includes - any environment variables defined before, the - binary, - sub-command optionally - only for selected binaries for which a rule exits, like apt-get, - options, e.g. --yes, - rest of the argument list, - raw string of the bash command, - sudo modifier.

func NewBashCommand

func NewBashCommand(envVarList map[string]string, bin string, subCommand string, optionMap map[string]string,
	argMap map[string]string, hasSudo bool, rawString string,
) BashCommand

func ParseBashCommand

func ParseBashCommand(bashCommandLex []string) BashCommand

ParseBashCommand parses a bash command from a []string format. The latter is currently obtained by github.com/google/shlex::Split. nolint:funlen

func ParseBashCommandList

func ParseBashCommandList(command interface{}) []BashCommand

ParseBashCommandList parses a list of bash commands, either from a raw string or buildkit::*instructions.RunCommand.

func (*BashCommand) ArgMap

func (bashCommand *BashCommand) ArgMap() map[string]string

ArgMap returns the argument list of the bash command.

func (*BashCommand) Bin

func (bashCommand *BashCommand) Bin() string

Bin returns the binary of the command.

func (*BashCommand) EnvVars

func (bashCommand *BashCommand) EnvVars() map[string]string

EnvVars returns the environment variables defined before the binary on the same line.

func (*BashCommand) HasSudo

func (bashCommand *BashCommand) HasSudo() bool

HasSudo tells whether the command has a sudo modifier in front of it.

func (*BashCommand) OptionKeyList

func (bashCommand *BashCommand) OptionKeyList() []string

OptionKeyList returns the options passed to the binary and/or the subcommand as a slice, but not the values.

func (*BashCommand) OptionList

func (bashCommand *BashCommand) OptionList() map[string]string

OptionList returns the options passed to the binary and/or the subcommand, like --yes.

func (*BashCommand) String

func (bashCommand *BashCommand) String() string

String returns the raw string of the bash command, that served as the basis of the parsing.

func (*BashCommand) SubCommand

func (bashCommand *BashCommand) SubCommand() string

SubCommand returns the optional subcommand for the selected set of pre-known binaries.

type BashCommandChain

type BashCommandChain struct {
	BashCommandList []BashCommand
	OperatorList    []string
}

BashCommandChain represents a chain of bash commands. e.g. "date; mkdir /test && ls test || echo "test" BashCommandList holds the individual bash commands, while OperatorList the operators - "&", "&&", "|", "||", ";".

func ParseBashCommandChain

func ParseBashCommandChain(command interface{}) BashCommandChain

ParseBashCommandChain parses a chain of bash commands separated by bash operators [&, &&, |, ||, ;, etc.]. Currently it can digest either a raw string or a buildkit::*instructions.RunCommand.

type RawDockerfileParser

type RawDockerfileParser struct {
	// contains filtered or unexported fields
}
var RawParser RawDockerfileParser = RawDockerfileParser{/* contains filtered or unexported fields */} // nolint:gochecknoglobals

func (*RawDockerfileParser) IsInitialized

func (r *RawDockerfileParser) IsInitialized() bool

func (*RawDockerfileParser) ParseDockerfile

func (r *RawDockerfileParser) ParseDockerfile(filePath string) error

func (*RawDockerfileParser) ParseRawLineRange

func (r *RawDockerfileParser) ParseRawLineRange(p []parser.Range) []string

func (*RawDockerfileParser) StringLocation

func (r *RawDockerfileParser) StringLocation(str string, window []parser.Range) [4]int

func (*RawDockerfileParser) StringSliceLocation

func (r *RawDockerfileParser) StringSliceLocation(strSlice []string, window []parser.Range) [][4]int

func (*RawDockerfileParser) UpdateRawStr

func (r *RawDockerfileParser) UpdateRawStr(str string)

Jump to

Keyboard shortcuts

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