From 5f435b488a47891e3030a19afa81ec22c62fc0e0 Mon Sep 17 00:00:00 2001 From: Finn Date: Sat, 12 Dec 2020 02:37:30 -0800 Subject: [PATCH] Fix when connect to socket happens --- cmd/signald-cli/cmd/root.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/signald-cli/cmd/root.go b/cmd/signald-cli/cmd/root.go index 6dd8b2d..9a96616 100644 --- a/cmd/signald-cli/cmd/root.go +++ b/cmd/signald-cli/cmd/root.go @@ -35,6 +35,13 @@ var RootCmd = &cobra.Command{ Use: "signald-cli", Short: "Interact with a running siangld instance", Long: `signald-cli is a command line tool to interact with signald.`, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + s = &signald.Signald{SocketPath: socketPath} + err := s.Connect() + if err != nil { + log.Fatal(err) + } + }, } // Execute adds all child commands to the root command sets flags appropriately. @@ -50,12 +57,6 @@ func init() { cobra.OnInitialize(initConfig) RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.signald-cli.yaml)") RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.sock", "the path to the signald socket file") - s = &signald.Signald{SocketPath: socketPath} - err := s.Connect() - if err != nil { - log.Fatal(err) - } - } // initConfig reads in config file and ENV variables if set.