M api/api.go => api/api.go +3 -0
@@ 13,6 13,9 @@ import (
"git.xenrox.net/~xenrox/srhtctl/helpers"
)
+// UserName is the sourcehut username
+var UserName string
+
type userStruct struct {
CName string `json:"canonical_name"`
Name string `json:"name"`
M cmd/root.go => cmd/root.go +3 -0
@@ 4,6 4,7 @@ import (
"fmt"
"os"
+ "git.xenrox.net/~xenrox/srhtctl/api"
"git.xenrox.net/~xenrox/srhtctl/config"
"github.com/spf13/cobra"
)
@@ 27,4 28,6 @@ func init() {
cobra.OnInitialize()
rootCmd.PersistentFlags().StringVar(&config.ConfigPath, "config", "", "Path to config.ini")
+
+ rootCmd.PersistentFlags().StringVarP(&api.UserName, "user", "u", "", "Sourcehut username")
}
A helpers/sourcehut.go => helpers/sourcehut.go +11 -0
@@ 0,0 1,11 @@
+package helpers
+
+import "strings"
+
+// TransformName takes a username and returns it as a canonical name
+func TransformCanonical(username string) string {
+ if strings.HasPrefix(username, "~") {
+ return username
+ }
+ return "~" + username
+}