From 1ac69b2c1602f0b61c8ed0b994208f253e8f1229 Mon Sep 17 00:00:00 2001 From: mikoto2000 Date: Sat, 22 Jun 2024 05:44:41 +0000 Subject: [PATCH] =?UTF-8?q?dockercompose.json=20=E3=81=AE=20dockerComposeF?= =?UTF-8?q?ile=20=E3=81=AE=E5=9E=8B=E4=B8=8D=E6=AD=A3=20=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devcontainer/DevcontainerJson.go | 2 +- devcontainer/devcontainer.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/devcontainer/DevcontainerJson.go b/devcontainer/DevcontainerJson.go index 94373b5..112361d 100644 --- a/devcontainer/DevcontainerJson.go +++ b/devcontainer/DevcontainerJson.go @@ -6,7 +6,7 @@ import ( // devcontainer.json のスキーマ(の一部) type DevcontainerJSON struct { - DockerComposeFile []string `json:"dockerComposeFile"` + DockerComposeFile interface{} `json:"dockerComposeFile"` } func UnmarshalDevcontainerJSON(data []byte) (DevcontainerJSON, error) { diff --git a/devcontainer/devcontainer.go b/devcontainer/devcontainer.go index 66d0088..4a4a35b 100644 --- a/devcontainer/devcontainer.go +++ b/devcontainer/devcontainer.go @@ -24,6 +24,7 @@ var devcontainreArgsPrefix = []string{"up"} // devcontainer でコンテナを立ち上げ、 Vim を転送し、実行する。 // 既存実装の都合上、configFilePath から configDirForDevcontainer を抽出している func ExecuteDevcontainer(args []string, devcontainerPath string, vimFilePath string, cdrPath, configFilePath string, vimrc string) { + vimFileName := filepath.Base(vimFilePath) // コマンドライン引数の末尾は `--workspace-folder` の値として使う @@ -335,7 +336,19 @@ func findDockerComposeFileDir() (string, error) { if err != nil { return "", err } - dockerComposeFilePath := filepath.Join(devcontainerJSONDir, devcontainerJSON.DockerComposeFile[0]) + + // string, []string を判別しながら docker-compose.yaml の場所を取得 + iDockerComposeFile := devcontainerJSON.DockerComposeFile + var dockerComposeFilePath string + switch v := iDockerComposeFile.(type) { + case string: + dockerComposeFilePath = v + case []interface{}: + vv := v[0].(string) + dockerComposeFilePath = filepath.Join(devcontainerJSONDir, vv) + default: + return "", errors.New("unknown type") + } dockerComposeFileDir := filepath.Dir(dockerComposeFilePath) // fmt.Printf("dockerComposeFileDir directory: %s\n", dockerComposeFileDir)