From 17eeb21f99e8bb46114538271b329642dbcfe66e Mon Sep 17 00:00:00 2001 From: Shawn Yu Date: Mon, 13 May 2024 11:28:22 -0400 Subject: [PATCH] feat: config command --- golang/cmd/config/config.go | 39 +++++++++++++++++++++++++++++++++++++ golang/main.go | 1 + 2 files changed, 40 insertions(+) create mode 100644 golang/cmd/config/config.go diff --git a/golang/cmd/config/config.go b/golang/cmd/config/config.go new file mode 100644 index 0000000..21beba0 --- /dev/null +++ b/golang/cmd/config/config.go @@ -0,0 +1,39 @@ +package config + +import ( + "github.com/charmbracelet/log" + "github.com/shawnyu5/gh-ac/cmd" + "github.com/shawnyu5/gh-ac/config" + "github.com/spf13/cobra" +) + +type cmdFlags struct { + hostName string +} + +var flags cmdFlags + +type Config struct { + // Custom hostname to run gh cli commands with + HostName string +} + +// configCmd represents the config command +var configCmd = &cobra.Command{ + Use: "config", + Short: "Set config values", + Run: func(cmd *cobra.Command, args []string) { + err := config.Write(config.Config{ + HostName: flags.hostName, + }) + log.Infof("Hostname set to %s", flags.hostName) + if err != nil { + log.Fatalf("Failed to write to config: %w", err) + } + }, +} + +func init() { + cmd.RootCmd.AddCommand(configCmd) + configCmd.Flags().StringVar(&flags.hostName, "hostname", "", "set the hostname") +} diff --git a/golang/main.go b/golang/main.go index 05198ce..f161232 100644 --- a/golang/main.go +++ b/golang/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/shawnyu5/gh-ac/cmd" + _ "github.com/shawnyu5/gh-ac/cmd/config" _ "github.com/shawnyu5/gh-ac/cmd/push" )