@@ -30,12 +30,14 @@ var (
3030 flagSessionToken string
3131 flagEnvFile string
3232 flagCreateDebugSession bool
33+ flagLocal bool
3334
3435 finalConfigFile string
3536 finalConcurrency string
3637 finalSessionToken string
3738 finalConfigValueSource string
3839 finalCreateDebugSession bool
40+ finalLocal bool
3941
4042 finalGraphFile string
4143 finalGraphArgs []string
@@ -109,6 +111,8 @@ var cmdRoot = &cobra.Command{
109111 })
110112 finalCreateDebugSession = finalCreateDebugSessionStr == "true" || finalCreateDebugSessionStr == "1"
111113
114+ finalLocal = flagLocal
115+
112116 // the block below is used to distinguish between implicit graph files (eg if defined in an env var) + graph flags
113117 // vs explicit graph file (eg provided by positional arg) + graph flags.
114118
@@ -147,6 +151,13 @@ var cmdRoot = &cobra.Command{
147151 return errors .New ("when using --create-debug-session, a graph file must be specified" )
148152 }
149153
154+ if finalLocal && finalSessionToken != "" {
155+ return errors .New ("--local and --session-token cannot be used together" )
156+ }
157+ if finalLocal && finalCreateDebugSession {
158+ return errors .New ("--local and --create-debug-session cannot be used together" )
159+ }
160+
150161 return nil
151162 },
152163}
@@ -155,6 +166,16 @@ func cmdRootRun(cmd *cobra.Command, args []string) {
155166
156167 utils .SetConcurrencyEnabled (finalConcurrency == "" || finalConcurrency == "true" || finalConcurrency == "1" )
157168
169+ // start a local WS server for local connections (eg the vscode extension)
170+ if finalLocal {
171+ err := sessions .RunLocalMode (finalConfigFile )
172+ if err != nil {
173+ utils .LogErr .Print (err .Error ())
174+ os .Exit (1 )
175+ }
176+ return
177+ }
178+
158179 // if we still have no graph file, go to Session Mode
159180 if finalGraphFile == "" || finalCreateDebugSession {
160181 trapfn := func () {
@@ -231,6 +252,7 @@ func init() {
231252 cmdRoot .Flags ().StringVar (& flagConcurrency , "concurrency" , "" , "Enable or disable concurrency" )
232253 cmdRoot .Flags ().StringVar (& flagSessionToken , "session-token" , "" , "The session token from your browser" )
233254 cmdRoot .Flags ().BoolVar (& flagCreateDebugSession , "create-debug-session" , false , "Create a debug session by connecting to the web app" )
255+ cmdRoot .Flags ().BoolVar (& flagLocal , "local" , false , "Start a local WebSocket server for direct editor connection" )
234256
235257 // disable interspersed flag parsing to allow passing arbitrary flags to graphs.
236258 // it stops cobra from parsing flags once it hits positional argument
0 commit comments