-
Notifications
You must be signed in to change notification settings - Fork 286
feat: Uses cwd as default workspace folder #956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
aae6c36
5828e43
b512bdf
231757e
f43c050
5751450
cdd73d8
a5b0b34
5d0778f
8564f2e
0064a09
28fc47f
352ddba
4c2a428
426589a
71a212a
5a7bf03
125b369
b51a60e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ function provisionOptions(y: Argv) { | |
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' }, | ||
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' }, | ||
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' }, | ||
'workspace-mount-consistency': { choices: ['consistent' as 'consistent', 'cached' as 'cached', 'delegated' as 'delegated'], default: 'cached' as 'cached', description: 'Workspace mount consistency.' }, | ||
'gpu-availability': { choices: ['all' as 'all', 'detect' as 'detect', 'none' as 'none'], default: 'detect' as 'detect', description: 'Availability of GPUs in case the dev container requires any. `all` expects a GPU to be available.' }, | ||
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' }, | ||
|
@@ -148,12 +148,6 @@ function provisionOptions(y: Argv) { | |
if (idLabels?.some(idLabel => !/.+=.+/.test(idLabel))) { | ||
throw new Error('Unmatched argument format: id-label must match <name>=<value>'); | ||
} | ||
if (!(argv['workspace-folder'] || argv['id-label'])) { | ||
throw new Error('Missing required argument: workspace-folder or id-label'); | ||
} | ||
if (!(argv['workspace-folder'] || argv['override-config'])) { | ||
throw new Error('Missing required argument: workspace-folder or override-config'); | ||
} | ||
const mounts = (argv.mount && (Array.isArray(argv.mount) ? argv.mount : [argv.mount])) as string[] | undefined; | ||
if (mounts?.some(mount => !mountRegex.test(mount))) { | ||
throw new Error('Unmatched argument format: mount must match type=<bind|volume>,source=<source>,target=<target>[,external=<true|false>]'); | ||
|
@@ -218,7 +212,7 @@ async function provision({ | |
'include-merged-configuration': includeMergedConfig, | ||
}: ProvisionArgs) { | ||
|
||
const workspaceFolder = workspaceFolderArg ? path.resolve(process.cwd(), workspaceFolderArg) : undefined; | ||
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg); | ||
const addRemoteEnvs = addRemoteEnv ? (Array.isArray(addRemoteEnv) ? addRemoteEnv as string[] : [addRemoteEnv]) : []; | ||
const addCacheFroms = addCacheFrom ? (Array.isArray(addCacheFrom) ? addCacheFrom as string[] : [addCacheFrom]) : []; | ||
const additionalFeatures = additionalFeaturesJson ? jsonc.parse(additionalFeaturesJson) as Record<string, string | boolean | Record<string, string | boolean>> : {}; | ||
|
@@ -507,7 +501,7 @@ function buildOptions(y: Argv) { | |
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' }, | ||
'docker-path': { type: 'string', description: 'Docker CLI path.' }, | ||
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' }, | ||
'workspace-folder': { type: 'string', required: true, description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' }, | ||
'config': { type: 'string', description: 'devcontainer.json path. The default is to use .devcontainer/devcontainer.json or, if that does not exist, .devcontainer.json in the workspace folder.' }, | ||
'log-level': { choices: ['info' as 'info', 'debug' as 'debug', 'trace' as 'trace'], default: 'info' as 'info', description: 'Log level.' }, | ||
'log-format': { choices: ['text' as 'text', 'json' as 'json'], default: 'text' as 'text', description: 'Log format.' }, | ||
|
@@ -680,7 +674,7 @@ async function doBuild({ | |
if (envFile) { | ||
composeGlobalArgs.push('--env-file', envFile); | ||
} | ||
|
||
const composeConfig = await readDockerComposeConfig(buildParams, composeFiles, envFile); | ||
const projectName = await getProjectName(params, workspace, composeFiles, composeConfig); | ||
const services = Object.keys(composeConfig.services || {}); | ||
|
@@ -752,7 +746,7 @@ function runUserCommandsOptions(y: Argv) { | |
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' }, | ||
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' }, | ||
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, For compatibility it might make sense to keep the existing behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the behavior meant to be for when a container ID AND workspace folder are provided right now? Would this impact them? If they pass the tests still, does this indicate the tests for container-id (and others) alone are incomplete? Does the path not already prefer those before the workspace folder? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When container id and workspace folder are given the container is looked up based on the container id. I think that was faster than the lookup by label. The tests are incomplete, additions appreciated. For consistency this change could assume the cwd as the workspace folder in all commands only when no container id and no id labels are given. Conveniently this case currently fails, so the change wouldn't break existing working setups. This should still cover most cases when run from a terminal because these rarely use the container id or id labels - I expect. Does this make sense? |
||
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' }, | ||
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' }, | ||
'id-label': { type: 'string', description: 'Id label(s) of the format name=value. If no --container-id is given the id labels will be used to look up the container. If no --id-label is given, one will be inferred from the --workspace-folder path.' }, | ||
|
@@ -784,9 +778,6 @@ function runUserCommandsOptions(y: Argv) { | |
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) { | ||
throw new Error('Unmatched argument format: remote-env must match <name>=<value>'); | ||
} | ||
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) { | ||
throw new Error('Missing required argument: One of --container-id, --id-label or --workspace-folder is required.'); | ||
} | ||
return true; | ||
}); | ||
} | ||
|
@@ -840,7 +831,7 @@ async function doRunUserCommands({ | |
await Promise.all(disposables.map(d => d())); | ||
}; | ||
try { | ||
const workspaceFolder = workspaceFolderArg ? path.resolve(process.cwd(), workspaceFolderArg) : undefined; | ||
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg); | ||
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined; | ||
const addRemoteEnvs = addRemoteEnv ? (Array.isArray(addRemoteEnv) ? addRemoteEnv as string[] : [addRemoteEnv]) : []; | ||
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined; | ||
|
@@ -954,7 +945,7 @@ function readConfigurationOptions(y: Argv) { | |
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' }, | ||
'docker-path': { type: 'string', description: 'Docker CLI path.' }, | ||
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' }, | ||
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' }, | ||
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' }, | ||
'id-label': { type: 'string', description: 'Id label(s) of the format name=value. If no --container-id is given the id labels will be used to look up the container. If no --id-label is given, one will be inferred from the --workspace-folder path.' }, | ||
|
@@ -974,9 +965,6 @@ function readConfigurationOptions(y: Argv) { | |
if (idLabels?.some(idLabel => !/.+=.+/.test(idLabel))) { | ||
throw new Error('Unmatched argument format: id-label must match <name>=<value>'); | ||
} | ||
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as with |
||
throw new Error('Missing required argument: One of --container-id, --id-label or --workspace-folder is required.'); | ||
} | ||
return true; | ||
}); | ||
} | ||
|
@@ -1012,7 +1000,7 @@ async function readConfiguration({ | |
}; | ||
let output: Log | undefined; | ||
try { | ||
const workspaceFolder = workspaceFolderArg ? path.resolve(process.cwd(), workspaceFolderArg) : undefined; | ||
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg); | ||
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined; | ||
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined; | ||
const overrideConfigFile = overrideConfig ? URI.file(path.resolve(process.cwd(), overrideConfig)) : undefined; | ||
|
@@ -1107,7 +1095,7 @@ async function readConfiguration({ | |
function outdatedOptions(y: Argv) { | ||
return y.options({ | ||
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' }, | ||
'workspace-folder': { type: 'string', required: true, description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' }, | ||
'config': { type: 'string', description: 'devcontainer.json path. The default is to use .devcontainer/devcontainer.json or, if that does not exist, .devcontainer.json in the workspace folder.' }, | ||
'output-format': { choices: ['text' as 'text', 'json' as 'json'], default: 'text', description: 'Output format.' }, | ||
'log-level': { choices: ['info' as 'info', 'debug' as 'debug', 'trace' as 'trace'], default: 'info' as 'info', description: 'Log level for the --terminal-log-file. When set to trace, the log level for --log-file will also be set to trace.' }, | ||
|
@@ -1209,7 +1197,7 @@ function execOptions(y: Argv) { | |
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' }, | ||
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' }, | ||
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' }, | ||
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' }, | ||
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' }, | ||
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' }, | ||
'id-label': { type: 'string', description: 'Id label(s) of the format name=value. If no --container-id is given the id labels will be used to look up the container. If no --id-label is given, one will be inferred from the --workspace-folder path.' }, | ||
|
@@ -1242,9 +1230,6 @@ function execOptions(y: Argv) { | |
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) { | ||
throw new Error('Unmatched argument format: remote-env must match <name>=<value>'); | ||
} | ||
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
throw new Error('Missing required argument: One of --container-id, --id-label or --workspace-folder is required.'); | ||
} | ||
return true; | ||
}); | ||
} | ||
|
@@ -1292,7 +1277,7 @@ export async function doExec({ | |
let output: Log | undefined; | ||
const isTTY = process.stdin.isTTY && process.stdout.isTTY || logFormat === 'json'; // If stdin or stdout is a pipe, we don't want to use a PTY. | ||
try { | ||
const workspaceFolder = workspaceFolderArg ? path.resolve(process.cwd(), workspaceFolderArg) : undefined; | ||
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg); | ||
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined; | ||
const addRemoteEnvs = addRemoteEnv ? (Array.isArray(addRemoteEnv) ? addRemoteEnv as string[] : [addRemoteEnv]) : []; | ||
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined; | ||
|
Uh oh!
There was an error while loading. Please reload this page.