mirror of
https://github.com/thegeeklab/drone-plugin-lib.git
synced 2024-11-22 00:40:39 +00:00
refcator: remove errors package (#5)
BREAKING CHANGE: The `errors` package was removed. Plugins should switch to the native `logrus.fatal()` function instead.
This commit is contained in:
parent
dcb03e1fa3
commit
341056af2a
@ -1,81 +0,0 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ExitCoder defines the interface for exit code handling.
|
||||
type ExitCoder interface {
|
||||
error
|
||||
Code() int
|
||||
Fields() logrus.Fields
|
||||
}
|
||||
|
||||
// ExitError simply implements the defined interface.
|
||||
type ExitError struct {
|
||||
message interface{}
|
||||
code int
|
||||
fields logrus.Fields
|
||||
}
|
||||
|
||||
// Error implements the ExitCoder interface.
|
||||
func (e ExitError) Error() string {
|
||||
return fmt.Sprintf("%v", e.message)
|
||||
}
|
||||
|
||||
// Code implements the ExitCoder interface.
|
||||
func (e ExitError) Code() int {
|
||||
return e.code
|
||||
}
|
||||
|
||||
// Fields implements the ExitCoder interface.
|
||||
func (e ExitError) Fields() logrus.Fields {
|
||||
return e.fields
|
||||
}
|
||||
|
||||
// ExitMessage initializes a new ExitCoder implementation.
|
||||
func ExitMessage(message interface{}) ExitError {
|
||||
return ExitError{
|
||||
message: message,
|
||||
code: 1,
|
||||
}
|
||||
}
|
||||
|
||||
// ExitMessagef initializes a new ExitCoder implementation.
|
||||
func ExitMessagef(format string, a ...interface{}) ExitError {
|
||||
return ExitError{
|
||||
message: fmt.Errorf(format, a...),
|
||||
code: 1,
|
||||
}
|
||||
}
|
||||
|
||||
// WithFields initializes a new ExitCoder implementation.
|
||||
func WithFields(message interface{}, fields logrus.Fields) ExitError {
|
||||
return ExitError{
|
||||
message: message,
|
||||
code: 1,
|
||||
fields: fields,
|
||||
}
|
||||
}
|
||||
|
||||
// HandleExit ist used within the main handler to exit properly.
|
||||
func HandleExit(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if e, ok := err.(ExitCoder); ok {
|
||||
if e.Error() != "" {
|
||||
logrus.WithFields(
|
||||
e.Fields(),
|
||||
).Error(
|
||||
e.Error(),
|
||||
)
|
||||
}
|
||||
|
||||
os.Exit(e.Code())
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
// Copyright (c) 2019, Drone Plugins project authors
|
||||
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
||||
|
||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Package urfave provides helpers for interacting with the `urfave/cli`
|
||||
// package when creating plugins for use by the Drone CI/CD service.
|
||||
//
|
||||
// Drone communicates to plugins by passing in environment variables that have
|
||||
// information on the currently executing build. The `urfave/cli` package can
|
||||
// read these environment variables and extract them into structs.
|
||||
//
|
||||
// import (
|
||||
// "github.com/thegeeklab/drone-plugin-lib/urfave"
|
||||
// "github.com/urfave/cli/v2"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// app := cli.NewApp()
|
||||
// app.Name = "plugin name"
|
||||
// app.Action = run
|
||||
// app.Flags = []cli.Flag{
|
||||
// // All my plugin flags
|
||||
// }
|
||||
//
|
||||
// app.Flags = append(
|
||||
// app.Flags,
|
||||
// urfave.Flags()...,
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// func run(ctx *cli.Context) error {
|
||||
// pipeline := urfave.FromContext(ctx)
|
||||
// ...
|
||||
// return nil
|
||||
// }
|
||||
package urfave
|
Loading…
Reference in New Issue
Block a user