From 29245066fe3081ecdf7a280ede4da9a9e47e0ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 20 Jun 2021 23:24:44 +0200 Subject: [PATCH] Add flag to read (canonical) username --- api/api.go | 3 +++ cmd/root.go | 3 +++ helpers/sourcehut.go | 11 +++++++++++ 3 files changed, 17 insertions(+) create mode 100644 helpers/sourcehut.go diff --git a/api/api.go b/api/api.go index a8f02be..7204311 100644 --- a/api/api.go +++ b/api/api.go @@ -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"` diff --git a/cmd/root.go b/cmd/root.go index 9eb0a19..d5c0ed9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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") } diff --git a/helpers/sourcehut.go b/helpers/sourcehut.go new file mode 100644 index 0000000..eebf7c2 --- /dev/null +++ b/helpers/sourcehut.go @@ -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 +} -- 2.44.0