Refactor code style for improved readability and consistency.

This commit is contained in:
Overlord committed 2026-10-14 00:28:32 +02:00
1 parent 463c013056
commit 94bfc87e9d
4 files changed
+118 -156

No files matched your search

+23 -33
View File
@@ -35,35 +35,31 @@ func main() {
func run(args []string, stdout, stderr io.Writer) int {
if len(args) > 0 {
switch args[0] {
case "config":
return runConfig(args[1:], stdout, stderr)
case "version":
printVersion(stdout)
return 0
case "check", "plugin":
_, _ = fmt.Fprintf(stderr, "dibs %s: not implemented yet\n", args[0])
return 1
case "help", "-h", "--help":
_, _ = fmt.Fprint(stdout, usage)
return 0
case "config":
return runConfig(args[1:], stdout, stderr)
case "version":
printVersion(stdout)
return 0
case "check", "plugin":
_, _ = fmt.Fprintf(stderr, "dibs %s: not implemented yet\n", args[0])
return 1
case "help", "-h", "--help":
_, _ = fmt.Fprint(stdout, usage)
return 0
}
}
flags, configPath := newFlagSet("dibs", stderr)
flags.Bool("headless", false, "run without the TUI, log to stdout")
if err := flags.Parse(args); err != nil {
return 2
}
if err := flags.Parse(args); err != nil { return 2 }
if flags.NArg() > 0 {
_, _ = fmt.Fprintf(stderr, "dibs: unknown command %q\n\n%s", flags.Arg(0), usage)
return 2
}
if _, ok := loadConfig(*configPath, stderr); !ok {
return 1
}
if _, ok := loadConfig(*configPath, stderr); !ok { return 1 }
_, _ = fmt.Fprintln(stderr, "dibs: watching is not implemented yet")
return 1
@@ -76,14 +72,10 @@ func runConfig(args []string, stdout, stderr io.Writer) int {
}
flags, configPath := newFlagSet("dibs config validate", stderr)
if err := flags.Parse(args[1:]); err != nil {
return 2
}
if err := flags.Parse(args[1:]); err != nil { return 2 }
cfg, ok := loadConfig(*configPath, stderr)
if !ok {
return 1
}
if !ok { return 1 }
urls := 0
for _, it := range cfg.Items {
@@ -98,9 +90,7 @@ func runConfig(args []string, stdout, stderr io.Writer) int {
}
func plural(n int, noun string) string {
if n == 1 {
return "1 " + noun
}
if n == 1 { return "1 " + noun }
return fmt.Sprintf("%d %ss", n, noun)
}
@@ -126,13 +116,13 @@ func loadConfig(path string, stderr io.Writer) (*config.Config, bool) {
if err != nil {
var errs config.Errors
switch {
case errors.As(err, &errs):
_, _ = fmt.Fprintln(stderr, errs)
_, _ = fmt.Fprintf(stderr, "%s in config\n", plural(len(errs), "problem"))
case errors.Is(err, fs.ErrNotExist):
_, _ = fmt.Fprintf(stderr, "dibs: no config at %s: create it or pass --config\n", path)
default:
_, _ = fmt.Fprintf(stderr, "dibs: %v\n", err)
case errors.As(err, &errs):
_, _ = fmt.Fprintln(stderr, errs)
_, _ = fmt.Fprintf(stderr, "%s in config\n", plural(len(errs), "problem"))
case errors.Is(err, fs.ErrNotExist):
_, _ = fmt.Fprintf(stderr, "dibs: no config at %s: create it or pass --config\n", path)
default:
_, _ = fmt.Fprintf(stderr, "dibs: %v\n", err)
}
return nil, false