github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/cmd/pyroscope/command/connect.go (about) 1 package command 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/pyroscope-io/pyroscope/pkg/cli" 7 "github.com/pyroscope-io/pyroscope/pkg/config" 8 "github.com/pyroscope-io/pyroscope/pkg/exec" 9 ) 10 11 func newConnectCmd(cfg *config.Connect) *cobra.Command { 12 vpr := newViper() 13 connectCmd := &cobra.Command{ 14 Use: "connect [flags]", 15 Short: "Connect to an existing process and profile it", 16 Args: cobra.NoArgs, 17 18 RunE: cli.CreateCmdRunFn(cfg, vpr, func(_ *cobra.Command, _ []string) error { 19 c, err := exec.NewConnect(cfg) 20 if err != nil { 21 return err 22 } 23 return c.Run() 24 }), 25 } 26 27 cli.PopulateFlagSet(cfg, connectCmd.Flags(), vpr) 28 _ = connectCmd.MarkFlagRequired("pid") 29 return connectCmd 30 }