satisfy linter

This commit is contained in:
2026-08-31 22:02:07 +02:00
parent cafc65aea7
commit 49eb1033ef
23 changed files with 327 additions and 220 deletions

View File

@@ -1,7 +1,7 @@
package cmd
var manpage = `
anydb
NAME
anydb - a personal key value store
SYNOPSIS
@@ -179,7 +179,7 @@ SUBCOMMANDS
the same meaning as in the list command. The "json" mode prints the raw
JSON representation of the whole database entry. Decryption will only
take place in "simple" and "json" mode. The "template" mode provides the
most flexibily, it is detailed in the section TEMPLATES.
most flexibility, it is detailed in the section TEMPLATES.
list
The list subcommand displays a list of all database entries.
@@ -407,7 +407,7 @@ TEMPLATES
Each template operates on one or more entries, no loop construct is
required, the template provided applies to every matching entry
separatley.
separateley.
The following template variables can be used:
@@ -417,6 +417,9 @@ TEMPLATES
"-s" flag so that values are included in output data stream.
Otherwise you can only use ".Preview".
Be careful if you use "-s" and ".Value" though: if a value is a
multiline string, it may clutter your output.
.Preview string
First line of entry value (if it is a string).

View File

@@ -112,19 +112,19 @@ func Get(conf *cfg.Config) *cobra.Command {
return err
}
if entry.Encrypted {
if entry.GetEncrypted() {
pass, err := getPassword()
if err != nil {
return err
}
clear, err := app.Decrypt(pass, []byte(entry.Value))
clear, err := app.Decrypt(pass, []byte(entry.GetValue()))
if err != nil {
return err
}
entry.Value = string(clear)
entry.Size = uint64(len(entry.Value))
entry.Size = uint64(len(entry.GetValue()))
entry.Encrypted = false
}
@@ -133,7 +133,8 @@ func Get(conf *cfg.Config) *cobra.Command {
}
cmd.PersistentFlags().StringVarP(&attr.File, "output", "o", "", "output value to file (ignores -m)")
cmd.PersistentFlags().StringVarP(&conf.Mode, "mode", "m", "", "output format (simple|wide|json|template) (default 'simple')")
cmd.PersistentFlags().StringVarP(&conf.Mode, "mode", "m", "",
"output format (simple|wide|json|template) (default 'simple')")
cmd.PersistentFlags().BoolVarP(&conf.NoHeaders, "no-headers", "n", false, "omit headers in tables")
cmd.PersistentFlags().BoolVarP(&conf.NoHumanize, "no-human", "N", false, "do not translate to human readable values")
cmd.PersistentFlags().StringVarP(&conf.Template, "template", "T", "", "go template for '-m template'")
@@ -216,7 +217,8 @@ func List(conf *cfg.Config) *cobra.Command {
},
}
cmd.PersistentFlags().StringVarP(&conf.Mode, "mode", "m", "", "output format (table|wide|json|template), wide is a verbose table. (default 'table')")
cmd.PersistentFlags().StringVarP(&conf.Mode, "mode", "m", "",
"output format (table|wide|json|template), wide is a verbose table. (default 'table')")
cmd.PersistentFlags().StringVarP(&conf.Template, "template", "T", "", "go template for '-m template'")
cmd.PersistentFlags().BoolVarP(&wide, "wide-output", "l", false, "output mode: wide")
cmd.PersistentFlags().BoolVarP(&conf.NoHeaders, "no-headers", "n", false, "omit headers in tables")

View File

@@ -1,3 +1,5 @@
package cmd
/*
Copyright © 2024 Thomas von Dein
@@ -14,7 +16,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"bytes"
@@ -25,11 +26,11 @@ import (
"os"
"os/exec"
"github.com/spf13/cobra"
"codeberg.org/scip/anydb/app"
"codeberg.org/scip/anydb/cfg"
"codeberg.org/scip/anydb/output"
"codeberg.org/scip/anydb/rest"
"github.com/spf13/cobra"
)
func Export(conf *cfg.Config) *cobra.Command {
@@ -57,6 +58,7 @@ func Export(conf *cfg.Config) *cobra.Command {
}
cmd.PersistentFlags().StringVarP(&attr.File, "output-file", "o", "", "filename or - for STDIN")
if err := cmd.MarkPersistentFlagRequired("output-file"); err != nil {
panic(err)
}
@@ -86,12 +88,14 @@ func Import(conf *cfg.Config) *cobra.Command {
}
fmt.Print(out)
return nil
},
}
cmd.PersistentFlags().StringVarP(&attr.File, "import-file", "i", "", "filename or - for STDIN")
cmd.PersistentFlags().StringArrayVarP(&attr.Tags, "tags", "t", nil, "tags, multiple allowed")
if err := cmd.MarkPersistentFlagRequired("import-file"); err != nil {
panic(err)
}
@@ -124,7 +128,6 @@ func Man(conf *cfg.Config) *cobra.Command {
man.Stderr = os.Stderr
err := man.Run()
if err != nil {
return fmt.Errorf("failed to execute 'less': %w", err)
}
@@ -205,19 +208,20 @@ func Edit(conf *cfg.Config) *cobra.Command {
return err
}
if len(entry.Value) == 0 && entry.Binary {
if len(entry.GetValue()) == 0 && entry.GetBinary() {
return errors.New("key contains binary uneditable content")
}
// decrypt if needed
if entry.Encrypted {
if entry.GetEncrypted() {
pass, err := getPassword()
if err != nil {
return err
}
password = pass
clear, err := app.Decrypt(pass, []byte(entry.Value))
clear, err := app.Decrypt(pass, []byte(entry.GetValue()))
if err != nil {
return err
}
@@ -232,7 +236,7 @@ func Edit(conf *cfg.Config) *cobra.Command {
// save file to a temp file, call the editor with it, read
// it back in and compare the content with the original
// one
newcontent, err := editContent(editor, string(entry.Value))
newcontent, err := editContent(editor, entry.GetValue())
if err != nil {
return err
}
@@ -328,7 +332,7 @@ func editContent(editor string, content string) (string, error) {
newcontentstr := string(newcontent)
if content == newcontentstr {
return "", fmt.Errorf("content not modified, aborting")
return "", errors.New("content not modified, aborting")
}
return newcontentstr, nil

View File

@@ -24,9 +24,9 @@ import (
"path/filepath"
"runtime/debug"
"github.com/spf13/cobra"
"codeberg.org/scip/anydb/app"
"codeberg.org/scip/anydb/cfg"
"github.com/spf13/cobra"
"github.com/tlinden/yadu"
)
@@ -69,7 +69,6 @@ func Execute() {
Short: "anydb",
Long: `A personal key value store`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var configs []string
if configfile != "" {
configs = []string{configfile}
@@ -110,12 +109,14 @@ func Execute() {
}
conf.DB = db
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if ShowVersion {
fmt.Printf("This is anydb version %s\n", cfg.Version)
return nil
}