diff --git a/cli/cli.go b/cli/cli.go new file mode 100644 index 0000000..43ef3f7 --- /dev/null +++ b/cli/cli.go @@ -0,0 +1,26 @@ +// Package cli provides utilities for writing command line utilities that +// interact with services. +package cli + +import "os" +import "fmt" +import "flag" +import "strings" + +// Sayf is like Printf, but prints the program name before the message. This is +// used for printing messages and errors. +func Sayf (format string, values ...any) { + Printf(os.Args[0] + ": " + format, values...) +} + +// Printf prints to stderr. +func Printf (format string, values ...any) { + fmt.Fprintf(flag.CommandLine.Output(), format, values...) +} + +// ServiceUser returns the system user that corresponds to the given service +// name. This is not necissarily equivalent Hnakra user, although it is good +// practice to have a 1:1 correspondance between them. +func ServiceUser (service string) string { + return "hn-" + strings.ToLower(service) +}