feat: support -copy-in-dir for easier debugging (#155)
Some checks are pending
Build / Goreleaser (push) Waiting to run
Build / Upload artifacts-${{ matrix.os }}-${{ matrix.arch }} (amd64_v3, darwin) (push) Blocked by required conditions
Build / Upload artifacts-${{ matrix.os }}-${{ matrix.arch }} (amd64_v3, linux) (push) Blocked by required conditions
Build / Upload artifacts-${{ matrix.os }}-${{ matrix.arch }} (amd64_v3, windows) (push) Blocked by required conditions
Build / Upload artifacts-${{ matrix.os }}-${{ matrix.arch }} (arm64_v8.0, darwin) (push) Blocked by required conditions
Build / Upload artifacts-${{ matrix.os }}-${{ matrix.arch }} (arm64_v8.0, linux) (push) Blocked by required conditions
Build / Upload artifacts-${{ matrix.os }}-${{ matrix.arch }} (arm64_v8.0, windows) (push) Blocked by required conditions

* feat: support -copy-in-dir for easier debugging

* fix: use relative path
This commit is contained in:
BoYanZh 2025-06-26 02:20:03 -04:00 committed by GitHub
parent 6bf9f2e224
commit 6211423165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import (
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"
@ -19,6 +20,7 @@ var (
transport = flag.String("transport", "websocket", "defines transport layer (websocket / grpc)")
wsURL = flag.String("ws-url", "ws://localhost:5050/stream", "HTTP server url")
grpcAddr = flag.String("grpc-addr", "localhost:5051", "GRPC server addr")
copyInDir = flag.String("copy-in-dir", "", "directory to copy files from")
)
const (
@ -61,6 +63,27 @@ func main() {
}
func run(sc Stream, args []string) (*model.Response, error) {
copyIn := make(map[string]model.CmdFile, 0)
if *copyInDir != "" {
_ = filepath.Walk(*copyInDir,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
absPath, err := filepath.Abs(path)
if err != nil {
return nil
}
relPath, err := filepath.Rel(*copyInDir, path)
if err != nil {
return nil
}
if !info.IsDir() {
copyIn[relPath] = model.CmdFile{Src: &absPath}
}
return nil
})
}
req := model.Request{
Cmd: []model.Cmd{{
Args: args,
@ -70,6 +93,7 @@ func run(sc Stream, args []string) (*model.Response, error) {
{StreamOut: true},
{StreamOut: true},
},
CopyIn: copyIn,
CPULimit: uint64(cpuLimit.Nanoseconds()),
ClockLimit: uint64(sessionLimit.Nanoseconds()),
MemoryLimit: memoryLimit,