mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
1998e211af
* remove docker from migrate cmd test * export migration status * [cli] add fake writer for spinner * Update console.go * Update migrate_test.go
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
const (
|
|
LEVEL_0 = iota
|
|
LEVEL_1
|
|
LEVEL_2
|
|
LEVEL_3
|
|
)
|
|
|
|
// PrefixWriter can write text at various indentation levels.
|
|
type PrefixWriter interface {
|
|
// Write writes text with the specified indentation level.
|
|
Write(level int, format string, a ...interface{})
|
|
// WriteLine writes an entire line with no indentation level.
|
|
WriteLine(a ...interface{})
|
|
// Flush forces indendation to be reset.
|
|
Flush()
|
|
}
|
|
|
|
// prefixWriter implements PrefixWriter
|
|
type prefixWriter struct {
|
|
out io.Writer
|
|
}
|
|
|
|
var _ PrefixWriter = &prefixWriter{}
|
|
|
|
// NewPrefixWriter creates a new PrefixWriter.
|
|
func NewPrefixWriter(out io.Writer) PrefixWriter {
|
|
return &prefixWriter{out: out}
|
|
}
|
|
|
|
func (pw *prefixWriter) Write(level int, format string, a ...interface{}) {
|
|
levelSpace := " "
|
|
prefix := ""
|
|
for i := 0; i < level; i++ {
|
|
prefix += levelSpace
|
|
}
|
|
fmt.Fprintf(pw.out, prefix+format, a...)
|
|
}
|
|
|
|
func (pw *prefixWriter) WriteLine(a ...interface{}) {
|
|
fmt.Fprintln(pw.out, a...)
|
|
}
|
|
|
|
func (pw *prefixWriter) Flush() {
|
|
if f, ok := pw.out.(flusher); ok {
|
|
f.Flush()
|
|
}
|
|
}
|
|
|
|
type flusher interface {
|
|
Flush()
|
|
}
|