Documentation ¶
Index ¶
- func Run(ctx context.Context, handlers ...Handler) error
- func SetDefault(c *Context)
- type Context
- func (c *Context) Context() context.Context
- func (c *Context) Next(in any) (any, error)
- func (c *Context) Run(ctx context.Context, handlers ...Handler) error
- func (c *Context) Silent(s ...bool) bool
- func (c *Context) Tracer(t ...tracer.Tracer) tracer.Tracer
- func (c *Context) Use(handles ...Handler) *Context
- func (c *Context) Workdir(wd ...string) string
- type Handler
- func AppendFile(path ...string) Handler
- func Cat(path string) Handler
- func Cd(path string) Handler
- func Echo(s string) Handler
- func ErrorHandler() Handler
- func Exec(name string, args ...string) Handler
- func Execf(format string, a ...any) Handler
- func Execs(cmd string) Handler
- func Gjson(path string) Handler
- func IfExists(path ...string) Handler
- func OpenFile(path string) Handler
- func Recover() Handler
- func Sed(cb func(i int, line string) string) Handler
- func Silent(s bool) Handler
- func Tee(w ...io.Writer) Handler
- func Tracer(t tracer.Tracer) Handler
- func Unmarshal(p parser.Parser, v any) Handler
- func WithReader(r io.Reader) Handler
- func WriteFile(path ...string) Handler
- type HandlerFunc
- type HandlersChain
- type HttpHandler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶ added in v0.1.2
Example ¶
package main import ( "context" "os" "github.com/tlipoca9/yevna" ) func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() err := yevna.Run( ctx, yevna.Exec("echo", "Hello, World!"), yevna.Tee(os.Stdout), ) if err != nil { panic(err) } }
Output: Hello, World!
func SetDefault ¶ added in v0.1.1
func SetDefault(c *Context)
Types ¶
type Context ¶ added in v0.1.0
type Context struct {
// contains filtered or unexported fields
}
type Handler ¶ added in v0.1.2
Handler is an interface that defines a handler.
func AppendFile ¶ added in v0.1.3
AppendFile returns a Handler that appends to a file. If the file does not exist, it will be created. If the file exists, it will be appended. If you want to truncate the file, use WriteFile instead. It sends input to next handler.
func Cat ¶ added in v0.1.3
Cat returns a Handler that reads a file. It drops the input and sends file content (io.Reader) to next handler.
func Cd ¶ added in v0.1.2
Cd returns a Handler that changes the working directory. It uses IfExists to check if the path exists. It sends input to next handler.
func Echo ¶ added in v0.1.2
Echo returns a Handler that echoes the string. If you want to read from a file, use Cat instead. If you want to read from a reader, use WithReader instead. It drops the input and sends string(converted to io.Reader) to next handler.
func ErrorHandler ¶ added in v0.1.3
func ErrorHandler() Handler
ErrorHandler returns a Handler that handles error. It prints the error using fmt.Printf("%+v\n", err).
func Exec ¶ added in v0.1.2
Exec returns a Handler that executes a command. It uses exec.CommandContext to execute the command.
- stdin is set to the input.
- stdout is sent to next handler.
- stderr is sent to os.Stderr if silent is false.
It starts the command and waits after the next handler is called.
func Execf ¶ added in v0.1.2
Execf returns a Handler that executes a command. It is a shortcut for Execs(fmt.Sprintf(format, a...)).
func Execs ¶ added in v0.1.2
Execs returns a Handler that executes a command. It uses shell.Fields to parse the command. It is a shortcut for Exec(shell.Fields(cmd)).
func IfExists ¶ added in v0.1.3
IfExists returns a Handler that checks if the file exists. If the file does not exist, it returns an error. If the file exists, it sends input to next handler.
func OpenFile ¶ added in v0.1.10
OpenFile returns a Handler that opens a file. It sends input to next handler.
func Recover ¶ added in v0.1.3
func Recover() Handler
Recover returns a Handler that recovers from panic. It wraps the panic error using errors.Wrap.
func Silent ¶ added in v0.1.2
Silent returns a Handler that sets the silent flag. If silent is true, Exec will not print stderr. If you want to disable tracing, use Tracer(tracer.Discard) instead. It sends input to next handler.
func Tee ¶ added in v0.1.2
Tee returns a Handler that writes to multiple writers. It uses io.Copy to copy the input to the writers and sends input to next handler.
func Tracer ¶ added in v0.1.2
Tracer returns a Handler that sets the tracer. If you want to disable tracing, use Tracer(tracer.Discard). It sends input to next handler.
func Unmarshal ¶ added in v0.1.2
Unmarshal returns a Handler that unmarshal the input. It uses the parser.Parser to unmarshal the input to v. It sends v to next handler.
func WithReader ¶ added in v0.1.2
WithReader returns a Handler that sets the reader. If you want to read from a file, use Cat instead. If you want to read from a string, use Echo instead. It drops the input and sends io.Reader to next handler.
type HandlerFunc ¶ added in v0.1.2
HandlerFunc defines a function type that implements Handler.
type HandlersChain ¶ added in v0.1.2
type HandlersChain []Handler
HandlersChain defines a Handler slice.
func (HandlersChain) Copy ¶ added in v0.1.3
func (c HandlersChain) Copy() HandlersChain
Copy returns a copy of the HandlersChain.
type HttpHandler ¶ added in v0.1.8
type HttpHandler struct {
// contains filtered or unexported fields
}
func HTTP ¶ added in v0.1.8
func HTTP() *HttpHandler
func (*HttpHandler) Handle ¶ added in v0.1.8
func (h *HttpHandler) Handle(c *Context, in any) (any, error)
func (*HttpHandler) MakeRequest ¶ added in v0.1.8
func (h *HttpHandler) MakeRequest(fn func(c *req.Client, in any) *req.Request) *HttpHandler
func (*HttpHandler) WithClient ¶ added in v0.1.8
func (h *HttpHandler) WithClient(client *req.Client) *HttpHandler