feat: wogihrsoiuvjsroirgj

This commit is contained in:
2025-12-24 14:55:33 -05:00
parent 1d8ecba118
commit 2c3ce9baf7
8 changed files with 204 additions and 26 deletions

28
internal/cli/arguments.go Normal file
View File

@@ -0,0 +1,28 @@
package cli
import (
"flag"
"fmt"
)
type CLIOptions struct {
Input string
Verbose bool
}
func ParseOptions(args []string) (*CLIOptions, error) {
// Parse flags and arguments.
verbose := flag.Bool("v", false, "Verbosity. If set, the program will print logs.")
flag.Parse()
if flag.NArg() == 0 {
return nil, fmt.Errorf("No input given.")
} else if flag.NArg() > 1 {
return nil, fmt.Errorf("More than 1 command-line argument.")
}
return &CLIOptions{
Input: flag.Arg(0),
Verbose: *verbose,
}, nil
}

15
internal/cli/exit.go Normal file
View File

@@ -0,0 +1,15 @@
package cli
import (
"fmt"
"os"
)
func HandleError(err error) {
if err == nil {
return
}
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

21
internal/cli/logger.go Normal file
View File

@@ -0,0 +1,21 @@
package cli
import (
"log/slog"
"os"
)
func GetLogger(o CLIOptions) *slog.Logger {
var level slog.Level
if o.Verbose {
level = slog.LevelInfo
} else {
level = slog.LevelError
}
return slog.New(
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: level,
}),
)
}