initial commit

This commit is contained in:
Jeremy Baxter 2026-03-18 21:07:12 +00:00
commit 8290a04536
3 changed files with 79 additions and 0 deletions

65
cli.go Normal file
View file

@ -0,0 +1,65 @@
package cli
import (
"fmt"
"os"
"path/filepath"
"git.sr.ht/~sircmpwn/getopt"
)
var undef = "(undefined)"
var program = undef
var version = undef
var progname = undef
func Init(prog, ver string) {
program = prog
version = ver
progname = filepath.Base(os.Args[0])
}
func Usage(args string) {
fmt.Fprintf(os.Stderr, "usage: %s %s", progname, args)
os.Exit(1)
}
func Version() {
fmt.Printf("%s version %s\n", program, version)
os.Exit(0)
}
func Warn(format string, args ...any) {
fmt.Fprintf(os.Stderr, "%s: %s\n",
progname, fmt.Sprintf(format, args...))
}
func Die(format string, args ...any) {
Warn(format, args...)
os.Exit(1)
}
func Fail(err error) {
Die("%s", err.Error())
}
func Bool(name string, value bool, usage string) *bool {
return getopt.Bool(name, value, usage)
}
func Int(name string, value int, usage string) *int {
return getopt.Int(name, value, usage)
}
func Uint(name string, value uint, usage string) *uint {
return getopt.Uint(name, value, usage)
}
func String(name, value, usage string) *string {
return getopt.String(name, value, usage)
}
func Parse() error {
return getopt.Parse()
}

5
go.mod Normal file
View file

@ -0,0 +1,5 @@
module git.baxters.nz/jeremy/cli
go 1.26.1
require git.sr.ht/~sircmpwn/getopt v1.0.0

9
go.sum Normal file
View file

@ -0,0 +1,9 @@
git.sr.ht/~sircmpwn/getopt v1.0.0 h1:/pRHjO6/OCbBF4puqD98n6xtPEgE//oq5U8NXjP7ROc=
git.sr.ht/~sircmpwn/getopt v1.0.0/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=