~xenrox/srhtctl

29245066fe3081ecdf7a280ede4da9a9e47e0ccd — Thorben Günther 2 years ago 5a1fcf2
Add flag to read (canonical) username
3 files changed, 17 insertions(+), 0 deletions(-)

M api/api.go
M cmd/root.go
A helpers/sourcehut.go
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
}