diff options
author | EuAndreh <eu@euandre.org> | 2025-05-15 11:33:42 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-05-15 11:37:28 -0300 |
commit | 40039d355287b43ccd42c58443bec914c8e57067 (patch) | |
tree | 7f57c6b85d9d9e57e6d93410c589d55df9044e37 /src/uuid.go | |
parent | po/: Remove extra headers from files (diff) | |
download | uuid-40039d355287b43ccd42c58443bec914c8e57067.tar.gz uuid-40039d355287b43ccd42c58443bec914c8e57067.tar.xz |
src/uuid.go: Use envT in run()
Diffstat (limited to 'src/uuid.go')
-rw-r--r-- | src/uuid.go | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/uuid.go b/src/uuid.go index c99f20b..bf7b783 100644 --- a/src/uuid.go +++ b/src/uuid.go @@ -67,6 +67,13 @@ type argsT struct{ version uint8 } +type envT struct{ + args argsT + in io.Reader + out io.Writer + err io.Writer +} + func NewV4From(r io.Reader) (UUID, error) { @@ -234,20 +241,22 @@ func getopt(allArgs []string, w io.Writer) (argsT, int) { }, 0 } -func run(args argsT, _ io.Reader, stdout io.Writer, stderr io.Writer) int { - switch args.action { +func run(env envT) int { + switch env.args.action { case actionType_generate: - if args.version == 4 { - fmt.Fprintf(stdout, "%v\n", NewV4().String()) - } else if args.version == 7 { - fmt.Fprintf(stdout, "%v\n", NewV7().String()) + if env.args.version == 4 { + fmt.Fprintf(env.out, "%v\n", NewV4().String()) + } else if env.args.version == 7 { + fmt.Fprintf(env.out, "%v\n", NewV7().String()) } return 0 case actionType_parse: - _, err := FromString(strings.TrimSpace(args.subArgs[0])) + _, err := FromString(strings.TrimSpace( + env.args.subArgs[0], + )) if err != nil { - fmt.Fprintln(stderr, err) + fmt.Fprintln(env.err, err) return 3 } else { return 0 @@ -260,9 +269,15 @@ func run(args argsT, _ io.Reader, stdout io.Writer, stderr io.Writer) int { func Main() { + gt.Init(Name, LOCALEDIR) args, rc := getopt(os.Args, os.Stderr) if rc != 0 { os.Exit(rc) } - os.Exit(run(args, os.Stdin, os.Stdout, os.Stderr)) + os.Exit(run(envT{ + args: args, + in: os.Stdin, + out: os.Stdout, + err: os.Stderr, + })) } |