Documentation
¶
Index ¶
- func MustInstallFlags(fs *pflag.FlagSet)
- type ANSIPrinter
- type Attachment
- type Format
- type GitHubPrinter
- type JSONPrinter
- type Message
- type Printer
- type Reporter
- func (r *Reporter) Debugf(format string, args ...any)
- func (r *Reporter) ErrorCount() int
- func (r *Reporter) Errorf(format string, args ...any)
- func (r *Reporter) Fatalf(format string, args ...any)
- func (r *Reporter) NoticeCount() int
- func (r *Reporter) Noticef(format string, args ...any)
- func (r *Reporter) Report(message *Message)
- func (r *Reporter) ReportFatal(message *Message)
- func (r *Reporter) ShowDebug(enable bool) *Reporter
- func (r *Reporter) WarningCount() int
- func (r *Reporter) Warningf(format string, args ...any)
- type Severity
- type TextPrinter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustInstallFlags ¶
MustInstallFlags installs the flags for the diagnostic package.
Types ¶
type ANSIPrinter ¶
type ANSIPrinter struct {
TextPrinter
}
ANSIPrinter prints diagnostic messages in plain text format with ANSI color codes, if the underlying writer is a terminal. If it is not a terminal, this type behaves like TextPrinter.
func (*ANSIPrinter) Print ¶
func (p *ANSIPrinter) Print(message *Message)
Print prints the given message in plain text format with ANSI color codes.
type Attachment ¶
type Attachment interface {
// contains filtered or unexported methods
}
Attachment represents an attachment that can be applied to a diagnostic message.
This follows the Go "options" pattern just to make it variadic and easy to set in a clean way.
func Column ¶
func Column(column int) Attachment
Column returns an attachment that sets the column of the message.
func ColumnRange ¶
func ColumnRange(column, columnEnd int) Attachment
ColumnRange returns an attachment that sets the column and end column of the message.
func File ¶
func File(file string) Attachment
File returns an attachment that sets the file of the message.
func Line ¶
func Line(line int) Attachment
Line returns an attachment that sets the line of the message.
func LineRange ¶
func LineRange(line, lineEnd int) Attachment
LineRange returns an attachment that sets the line and end line of the message.
func Title ¶
func Title(title string) Attachment
Title returns an attachment that sets the title of the message.
type Format ¶
type Format string
Format represents the format type of the diagnostic output.
func ParseFormat ¶
ParseFormat parses the given string into a Format.
type GitHubPrinter ¶
type GitHubPrinter struct {
// W is the writer to write the JSON output to. If not set, it defaults to
// os.Stdout.
W io.Writer
}
GitHubPrinter prints diagnostic messages in the format expected by GitHub Actions. See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
func (*GitHubPrinter) Print ¶
func (p *GitHubPrinter) Print(message *Message)
Print prints the given message in the format expected by GitHub Actions.
type JSONPrinter ¶
type JSONPrinter struct {
// W is the writer to write the JSON output to. If not set, it defaults to
// os.Stdout.
W io.Writer
// Indent specifies whether the JSON output should be indented.
Indent bool
}
JSONPrinter prints diagnostic messages in JSON format.
func (*JSONPrinter) Print ¶
func (p *JSONPrinter) Print(message *Message)
Print prints the given message in JSON format.
type Message ¶
type Message struct {
// Severity is the severity of the message (required).
Severity Severity `json:"severity"`
// Body is the body of the message (required).
Body string `json:"body"`
// Title is the title of the message (optional).
Title string `json:"title,omitempty"`
// File is the file name where the message originated (optional).
File string `json:"file,omitempty"`
// Line is the line number where the message originated (optional).
Line int `json:"line,omitempty"`
// Column is the column number where the message originated (optional).
Column int `json:"column,omitempty"`
// LineEnd is the end line number where the message originated (optional).
LineEnd int `json:"line-end,omitempty"`
// ColumnEnd is the end column number where the message originated (optional).
ColumnEnd int `json:"column-end,omitempty"`
}
Message represents a diagnostic message. The fields in this message map to the message fields as defined in https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
func NewMessage ¶
NewMessage creates a new message with the given severity and body.
func (*Message) With ¶
func (m *Message) With(attachments ...Attachment) *Message
With applies the attachments to the message.
type Printer ¶
type Printer interface {
// Print prints the given message.
Print(message *Message)
}
Printer represents a Printer that can print diagnostic messages.
var DefaultPrinter Printer = &TextPrinter{W: os.Stdout}
DefaultPrinter is the default printer to use if no other printer is specified.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter represents an emitter that can emit diagnostic messages.
func NewReporter ¶
NewReporter creates a new reporter with the given printer.
func ReporterFromFlags ¶
ReporterFromFlags returns the printer based on the flags. The reporter will always use stderr by default, since reports need to be unbuffered messages.
func ReporterFromFlagsWithWriter ¶
ReporterFromFlagsWithWriter returns the printer based on the flags with the given writer.
func (*Reporter) ErrorCount ¶
ErrorCount returns the number of errors emitted.
func (*Reporter) NoticeCount ¶
NoticeCount returns the number of notices emitted.
func (*Reporter) ReportFatal ¶
ReportFatal emits a fatal error and exits the program.
func (*Reporter) WarningCount ¶
WarningCount returns the number of warnings emitted.
type Severity ¶
type Severity string
Severity represents the severity of a diagnostic message.
const ( // SeverityError represents an error message. SeverityError Severity = "error" // SeverityWarning represents a warning message. SeverityWarning Severity = "warning" // SeverityNotice represents a notice message. SeverityNotice Severity = "notice" // SeverityDebug represents a debug message. SeverityDebug Severity = "debug" )
type TextPrinter ¶
type TextPrinter struct {
// W is the writer to write the JSON output to. If not set, it defaults to
// os.Stdout.
W io.Writer
}
TextPrinter prints diagnostic messages in plain text format. This will ignore any source-location information from the message and only print the severity and body.
func (*TextPrinter) Print ¶
func (p *TextPrinter) Print(message *Message)
Print prints the given message in plain text format.