From 9d8e6e8e24e5195faf70e33f318b29ef2fc91194 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 30 May 2023 18:00:26 -0400 Subject: [PATCH] Added cli package --- cli/cli.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cli/cli.go 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) +}