From 7828f8d92fa87a23fbfe4d252b214b8a64fb6b77 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 29 Jun 2021 16:56:00 +0100 Subject: [PATCH] envexp: drop package in favour of asciigoat.org/parsers/shexp Signed-off-by: Alejandro Mery --- envexp/expand.go | 39 ----------------------------- envexp/global.go | 39 ----------------------------- envexp/reader.go | 64 ------------------------------------------------ 3 files changed, 142 deletions(-) delete mode 100644 envexp/expand.go delete mode 100644 envexp/global.go delete mode 100644 envexp/reader.go diff --git a/envexp/expand.go b/envexp/expand.go deleted file mode 100644 index 41ccdc6..0000000 --- a/envexp/expand.go +++ /dev/null @@ -1,39 +0,0 @@ -// Package envexp provides environment variable expansion using sh syntax -package envexp - -import ( - "os" -) - -// A VarGetter is a function that for a given paramenter -// returns a string representing its value -type VarGetter func(key string) string - -// A Expander is an object that you can use to Expand strings -type Expander struct { - get VarGetter -} - -// NewExpander allocates a new Expander using a -// given VarGetter, or os.Getenv if none is given -func NewExpander(f VarGetter) *Expander { - if f == nil { - f = os.Getenv - } - - return &Expander{ - get: f, - } -} - -// Get resolves a variable name as the given Expander -// would do -func (exp *Expander) Get(key string) string { - return exp.get(key) -} - -// Expand expands a string using the VarGetter -// defined for the given Expander -func (exp *Expander) Expand(s string) string { - return s -} diff --git a/envexp/global.go b/envexp/global.go deleted file mode 100644 index e47516b..0000000 --- a/envexp/global.go +++ /dev/null @@ -1,39 +0,0 @@ -package envexp - -import ( - "io" - "os" -) - -var envExpander = &Expander{ - get: os.Getenv, -} - -// Expand uses os.GetEnv() to expand a given string -func Expand(s string) string { - return envExpander.Expand(s) -} - -// NewReaderSize creates a new Reader wrapper with a given buffer size -// using os.GetEnv() for expanding -func NewReaderSize(in io.Reader, size int) *Reader { - return envExpander.NewReaderSize(in, size) -} - -// NewReader creates a new Reader wrapper -// using os.GetEnv() for expanding -func NewReader(in io.Reader) *Reader { - return envExpander.NewReader(in) -} - -// NewReaderFileSize creates a new Reader for a file -// with a given buffer size using os.GetEnv() for expanding -func NewReaderFileSize(filename string, size int) (*Reader, error) { - return envExpander.NewReaderFileSize(filename, size) -} - -// NewReaderFile creates a new Reader for a file -// using os.GetEnv() for expanding -func NewReaderFile(filename string) (*Reader, error) { - return envExpander.NewReaderFile(filename) -} diff --git a/envexp/reader.go b/envexp/reader.go deleted file mode 100644 index e408f4f..0000000 --- a/envexp/reader.go +++ /dev/null @@ -1,64 +0,0 @@ -package envexp - -import ( - "bytes" - "io" - "os" -) - -const ( - MinimumBufferSize = 32 - DefaultBufferSize = 4096 -) - -type Reader struct { - exp *Expander - in io.Reader - buf *bytes.Buffer - out *bytes.Buffer -} - -func (rd *Reader) Read(b []byte) (int, error) { - return rd.in.Read(b) -} - -func (rd *Reader) Close() error { - if f, ok := rd.in.(io.Closer); ok { - return f.Close() - } - return nil -} - -// -// Constructors -// -func (exp *Expander) NewReaderSize(in io.Reader, size int) *Reader { - if size < MinimumBufferSize { - size = DefaultBufferSize - } - - return &Reader{ - exp: exp, - in: in, - buf: bytes.NewBuffer(make([]byte, 0, size)), - out: bytes.NewBuffer(make([]byte, 0, size)), - } -} - -func (exp *Expander) NewReader(in io.Reader) *Reader { - return exp.NewReaderSize(in, DefaultBufferSize) -} - -func (exp *Expander) NewReaderFileSize(filename string, size int) (*Reader, error) { - f, err := os.Open(filename) - if err != nil { - return nil, err - } - - rd := exp.NewReaderSize(f, size) - return rd, nil -} - -func (exp *Expander) NewReaderFile(filename string) (*Reader, error) { - return exp.NewReaderFileSize(filename, DefaultBufferSize) -}