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.