Skip to content

Commit 5a7bf03

Browse files
committed
♻️ Uses Yargs Default for other commands.
And fixes broken test syntaxes
1 parent 71a212a commit 5a7bf03

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/spec-node/devContainersSpecCLI.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function provisionOptions(y: Argv) {
103103
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
104104
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' },
105105
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' },
106-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
106+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' },
107107
'workspace-mount-consistency': { choices: ['consistent' as 'consistent', 'cached' as 'cached', 'delegated' as 'delegated'], default: 'cached' as 'cached', description: 'Workspace mount consistency.' },
108108
'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.' },
109109
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' },
@@ -212,7 +212,7 @@ async function provision({
212212
'include-merged-configuration': includeMergedConfig,
213213
}: ProvisionArgs) {
214214

215-
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg ?? '.');
215+
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg);
216216
const addRemoteEnvs = addRemoteEnv ? (Array.isArray(addRemoteEnv) ? addRemoteEnv as string[] : [addRemoteEnv]) : [];
217217
const addCacheFroms = addCacheFrom ? (Array.isArray(addCacheFrom) ? addCacheFrom as string[] : [addCacheFrom]) : [];
218218
const additionalFeatures = additionalFeaturesJson ? jsonc.parse(additionalFeaturesJson) as Record<string, string | boolean | Record<string, string | boolean>> : {};
@@ -674,7 +674,7 @@ async function doBuild({
674674
if (envFile) {
675675
composeGlobalArgs.push('--env-file', envFile);
676676
}
677-
677+
678678
const composeConfig = await readDockerComposeConfig(buildParams, composeFiles, envFile);
679679
const projectName = await getProjectName(params, workspace, composeFiles, composeConfig);
680680
const services = Object.keys(composeConfig.services || {});
@@ -746,7 +746,7 @@ function runUserCommandsOptions(y: Argv) {
746746
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
747747
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' },
748748
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' },
749-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
749+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' },
750750
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' },
751751
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' },
752752
'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.' },
@@ -831,7 +831,7 @@ async function doRunUserCommands({
831831
await Promise.all(disposables.map(d => d()));
832832
};
833833
try {
834-
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg ?? '.');
834+
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg);
835835
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined;
836836
const addRemoteEnvs = addRemoteEnv ? (Array.isArray(addRemoteEnv) ? addRemoteEnv as string[] : [addRemoteEnv]) : [];
837837
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined;
@@ -945,7 +945,7 @@ function readConfigurationOptions(y: Argv) {
945945
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' },
946946
'docker-path': { type: 'string', description: 'Docker CLI path.' },
947947
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
948-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
948+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' },
949949
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' },
950950
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' },
951951
'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.' },
@@ -1000,7 +1000,7 @@ async function readConfiguration({
10001000
};
10011001
let output: Log | undefined;
10021002
try {
1003-
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg ?? '.');
1003+
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg);
10041004
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined;
10051005
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined;
10061006
const overrideConfigFile = overrideConfig ? URI.file(path.resolve(process.cwd(), overrideConfig)) : undefined;
@@ -1095,7 +1095,7 @@ async function readConfiguration({
10951095
function outdatedOptions(y: Argv) {
10961096
return y.options({
10971097
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' },
1098-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
1098+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' },
10991099
'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.' },
11001100
'output-format': { choices: ['text' as 'text', 'json' as 'json'], default: 'text', description: 'Output format.' },
11011101
'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.' },
@@ -1127,7 +1127,7 @@ async function outdated({
11271127
};
11281128
let output: Log | undefined;
11291129
try {
1130-
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg ?? '.');
1130+
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg);
11311131
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined;
11321132
const cliHost = await getCLIHost(workspaceFolder, loadNativeModule, logFormat === 'text');
11331133
const extensionPath = path.join(__dirname, '..', '..');
@@ -1197,7 +1197,7 @@ function execOptions(y: Argv) {
11971197
'docker-compose-path': { type: 'string', description: 'Docker Compose CLI path.' },
11981198
'container-data-folder': { type: 'string', description: 'Container data folder where user data inside the container will be stored.' },
11991199
'container-system-data-folder': { type: 'string', description: 'Container system data folder where system data inside the container will be stored.' },
1200-
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
1200+
'workspace-folder': { type: 'string', description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.', default: '.', defaultDescription: 'Current Working Directory' },
12011201
'mount-workspace-git-root': { type: 'boolean', default: true, description: 'Mount the workspace using its Git root.' },
12021202
'container-id': { type: 'string', description: 'Id of the container to run the user commands for.' },
12031203
'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.' },
@@ -1277,7 +1277,7 @@ export async function doExec({
12771277
let output: Log | undefined;
12781278
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.
12791279
try {
1280-
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg ?? '.');
1280+
const workspaceFolder = path.resolve(process.cwd(), workspaceFolderArg);
12811281
const providedIdLabels = idLabel ? Array.isArray(idLabel) ? idLabel as string[] : [idLabel] : undefined;
12821282
const addRemoteEnvs = addRemoteEnv ? (Array.isArray(addRemoteEnv) ? addRemoteEnv as string[] : [addRemoteEnv]) : [];
12831283
const configFile = configParam ? URI.file(path.resolve(process.cwd(), configParam)) : undefined;

src/test/cli.exec.base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export function describeTests1({ text, options }: BuildKitOption) {
3030
const testFolder = `${__dirname}/configs/image`;
3131
beforeEach(async () => containerId = (await devContainerUp(cli, testFolder, options)).containerId);
3232
afterEach(async () => await devContainerDown({ containerId }));
33-
it'should execute successfully', async () => {
33+
it('should execute successfully', async () => {
3434
const res = await shellBufferExec(`${cli} exec --workspace-folder ${testFolder} echo hi`);
3535
assert.strictEqual(res.code, 0);
3636
assert.equal(res.signal, undefined);
3737
assert.strictEqual(res.stdout.toString(), 'hi\n');
3838
});
39-
it'should execute without a workspace folder', async () => {
39+
it('should execute without a workspace folder', async () => {
4040
const res = await shellBufferExec(`${cli} exec echo hi`, { cwd: testFolder});
4141
assert.strictEqual(res.code, 0);
4242
assert.equal(res.signal, undefined);

src/test/container-features/lockfile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('Lockfile', function () {
125125
assert.strictEqual(foo.latestMajor, '2');
126126
});
127127

128-
it'outdated command with text output', async () => {
128+
it('outdated command with text output', async () => {
129129
const workspaceFolder = path.join(__dirname, 'configs/lockfile-outdated-command');
130130

131131
const res = await shellExec(`${cli} outdated --workspace-folder ${workspaceFolder} --output-format text`);
@@ -152,7 +152,7 @@ describe('Lockfile', function () {
152152
assert.ok(!response.includes('myfeatures'));
153153
});
154154

155-
it'outdated command without workspace', async () => {
155+
it('outdated command without workspace', async () => {
156156
const workspaceFolder = path.join(__dirname, 'configs/lockfile-outdated-command');
157157

158158
const res = await shellExec(`${cli} outdated --output-format text`, { cwd: workspaceFolder });

0 commit comments

Comments
 (0)