Skip to content

Commit 818bce1

Browse files
Merge pull request #21 from actionforge/feature/local-server
Add local WebSocket server mode for direct editor connection
2 parents 58070c2 + 0a6b2bd commit 818bce1

18 files changed

Lines changed: 1602 additions & 1042 deletions

cmd/cmd_root.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

nodes/dir-walk@v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func walk(root string, opts walkOpts, pattern []string, items map[string]os.File
154154
})
155155

156156
} else {
157-
entries, err := os.ReadDir(root)
157+
entries, err := os.ReadDir(filepath.Clean(root))
158158
if err != nil {
159159
return "", core.CreateErr(nil, err, "failed to read directory")
160160
}

nodes/run@v1.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ func runCommand(c *core.ExecutionState, shell string, script *string, args []str
249249
curEnvMap["PYTHONIOENCODING"] = "utf-8"
250250

251251
args = append([]string{scriptPath}, args...)
252+
default:
253+
return "", 0, core.CreateErr(c, nil, "unsupported shell: %s", shell)
252254
}
253255
cmd = exec.Command(shell, args...)
254256

0 commit comments

Comments
 (0)