update linter config, satisfy linter (#28)

This commit is contained in:
T. von Dein
2026-08-31 22:06:25 +02:00
parent 5c9900d985
commit 1d45b2c6fe
24 changed files with 331 additions and 221 deletions

View File

@@ -26,12 +26,12 @@ import (
"strings"
tpl "text/template"
"codeberg.org/scip/anydb/app"
"codeberg.org/scip/anydb/cfg"
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/renderer"
"github.com/olekukonko/tablewriter/tw"
"codeberg.org/scip/anydb/app"
"codeberg.org/scip/anydb/cfg"
)
func List(writer io.Writer, conf *cfg.Config, entries app.DbEntries) error {
@@ -54,6 +54,7 @@ func ListJson(writer io.Writer, conf *cfg.Config, entries app.DbEntries) error {
}
fmt.Println(string(jsonentries))
return nil
}
@@ -67,6 +68,7 @@ func ListTemplate(writer io.Writer, conf *cfg.Config, entries app.DbEntries) err
for _, row := range entries {
buf.Reset()
err = tmpl.Execute(&buf, row)
if err != nil {
return fmt.Errorf("failed to execute output template: %w", err)
@@ -133,28 +135,27 @@ func ListTable(writer io.Writer, conf *cfg.Config, entries app.DbEntries) error
case true:
if err :=
table.Append([]string{
row.Key,
strings.Join(row.Tags, ","),
strconv.FormatUint(row.Size, 10),
row.Created.AsTime().Format("02.01.2006T03:04.05"),
row.Preview,
row.GetKey(),
strings.Join(row.GetTags(), ","),
strconv.FormatUint(row.GetSize(), 10),
row.GetCreated().AsTime().Format("02.01.2006T03:04.05"),
row.GetPreview(),
}); err != nil {
return fmt.Errorf("failed to add data to table: %w", err)
}
default:
if err := table.Append([]string{
row.Key,
strings.Join(row.Tags, ","),
humanize.Bytes(uint64(row.Size)),
humanize.Time(row.Created.AsTime()),
row.Preview,
row.GetKey(),
strings.Join(row.GetTags(), ","),
humanize.Bytes(row.GetSize()),
humanize.Time(row.GetCreated().AsTime()),
row.GetPreview(),
}); err != nil {
return fmt.Errorf("failed to add data to table: %w", err)
}
}
} else {
if err := table.Append([]string{row.Key, row.Preview}); err != nil {
if err := table.Append([]string{row.GetKey(), row.GetPreview()}); err != nil {
return fmt.Errorf("failed to add data to table: %w", err)
}
}

View File

@@ -24,11 +24,11 @@ import (
"os"
"reflect"
"github.com/dustin/go-humanize"
"codeberg.org/scip/anydb/app"
"codeberg.org/scip/anydb/cfg"
"github.com/dustin/go-humanize"
"golang.org/x/term"
//"github.com/alecthomas/repr"
// "github.com/alecthomas/repr"
)
func Print(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.DbEntry) error {
@@ -40,17 +40,18 @@ func Print(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.DbEn
switch conf.Mode {
case "simple", "":
if entry.Binary {
if entry.GetBinary() {
if isatty {
fmt.Println("binary data omitted")
} else {
if _, err := os.Stdout.WriteString(entry.Value); err != nil {
if _, err := os.Stdout.WriteString(entry.GetValue()); err != nil {
return err
}
}
} else {
fmt.Print(string(entry.Value))
if entry.Value[entry.Size-1] != '\n' {
fmt.Print(entry.GetValue())
if entry.GetValue()[entry.GetSize()-1] != '\n' {
// always add a terminal newline
fmt.Println()
}
@@ -72,8 +73,10 @@ func Print(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.DbEn
}
func WriteFile(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.DbEntry) error {
var fileHandle *os.File
var err error
var (
fileHandle *os.File
err error
)
if attr.File == "-" {
fileHandle = os.Stdout
@@ -92,10 +95,10 @@ func WriteFile(writer io.Writer, conf *cfg.Config, attr *app.DbAttr, entry *app.
}
// actually write file content
_, err = fileHandle.WriteString(entry.Value)
_, err = fileHandle.WriteString(entry.GetValue())
if !entry.Binary {
if entry.Value[entry.Size-1] != '\n' {
if !entry.GetBinary() {
if entry.GetValue()[entry.GetSize()-1] != '\n' {
// always add a terminal newline
_, err = fileHandle.Write([]byte{'\n'})
}
@@ -137,7 +140,7 @@ func Info(writer io.Writer, conf *cfg.Config, info *app.DbInfo) error {
if conf.Debug {
val := reflect.ValueOf(&bucket.Stats).Elem()
for i := 0; i < val.NumField(); i++ {
for i := range val.NumField() {
if _, err := fmt.Fprintf(writer, "%19s: %v\n", val.Type().Field(i).Name, val.Field(i)); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}