Skip to content

Commit bbb3c3a

Browse files
committed
cwd default for build, runusercommands, readconfig
1 parent afc2a34 commit bbb3c3a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/spec-node/devContainersSpecCLI.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ function buildOptions(y: Argv) {
507507
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' },
508508
'docker-path': { type: 'string', description: 'Docker CLI path.' },
509509
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
510-
'workspace-folder': { type: 'string', required: true, description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
510+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path. If not provided, defaults to the current directory.' },
511511
'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.' },
512512
'log-level': { choices: ['info' as 'info', 'debug' as 'debug', 'trace' as 'trace'], default: 'info' as 'info', description: 'Log level.' },
513513
'log-format': { choices: ['text' as 'text', 'json' as 'json'], default: 'text' as 'text', description: 'Log format.' },
@@ -526,6 +526,12 @@ function buildOptions(y: Argv) {
526526
'experimental-lockfile': { type: 'boolean', default: false, hidden: true, description: 'Write lockfile' },
527527
'experimental-frozen-lockfile': { type: 'boolean', default: false, hidden: true, description: 'Ensure lockfile remains unchanged' },
528528
'omit-syntax-directive': { type: 'boolean', default: false, hidden: true, description: 'Omit Dockerfile syntax directives' },
529+
})
530+
.check(argv => {
531+
if (!argv['workspace-folder']) {
532+
argv['workspace-folder'] = process.cwd();
533+
}
534+
return true;
529535
});
530536
}
531537

@@ -752,7 +758,7 @@ function runUserCommandsOptions(y: Argv) {
752758
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
753759
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' },
754760
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' },
755-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
761+
'workspace-folder': { type: 'string', description: 'Workspace folder path.The devcontainer.json will be looked up relative to this path. If --container-id, --id-label, and --workspace-folder are not provided, this defaults to the current directory.' },
756762
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' },
757763
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' },
758764
'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.' },
@@ -785,7 +791,7 @@ function runUserCommandsOptions(y: Argv) {
785791
throw new Error('Unmatched argument format: remote-env must match <name>=<value>');
786792
}
787793
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) {
788-
throw new Error('Missing required argument: One of --container-id, --id-label or --workspace-folder is required.');
794+
argv['workspace-folder'] = process.cwd();
789795
}
790796
return true;
791797
});
@@ -954,7 +960,7 @@ function readConfigurationOptions(y: Argv) {
954960
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' },
955961
'docker-path': { type: 'string', description: 'Docker CLI path.' },
956962
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
957-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
963+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path. If --container-id, --id-label, and --workspace-folder are not provided, this defaults to the current directory.' },
958964
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' },
959965
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' },
960966
'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.' },
@@ -975,7 +981,7 @@ function readConfigurationOptions(y: Argv) {
975981
throw new Error('Unmatched argument format: id-label must match <name>=<value>');
976982
}
977983
if (!argv['container-id'] && !idLabels?.length && !argv['workspace-folder']) {
978-
throw new Error('Missing required argument: One of --container-id, --id-label or --workspace-folder is required.');
984+
argv['workspace-folder'] = process.cwd();
979985
}
980986
return true;
981987
});

0 commit comments

Comments
 (0)