Skip to content

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

ekwoka
Copy link

@ekwoka ekwoka commented Feb 13, 2025

This basically makes the equivalent of --workspace-folder . the default.

I'd imagine that this is 99% of use cases already, and those that need something else will know they need something else.

I think I covered all the commands this would apply to with the tests.

@ekwoka ekwoka requested a review from a team as a code owner February 13, 2025 10:17
@ekwoka
Copy link
Author

ekwoka commented Feb 13, 2025

@microsoft-github-policy-service agree

@julienp17
Copy link

I agree that this would make life easier and I don't understand why it wasn't by default

Copy link
Contributor

@chrmarti chrmarti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Left a few comments.

@@ -507,7 +497,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.' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that the current working directory is used by default. (Also in a few other places in this file.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I actually just moved the default to the yargs entirely, so no need to manually handle null.

@ekwoka ekwoka force-pushed the default-workspace-folder branch from 292e231 to 4c2a428 Compare March 3, 2025 06:07
chrmarti
chrmarti previously approved these changes Mar 12, 2025
Copy link
Contributor

@chrmarti chrmarti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@ekwoka
Copy link
Author

ekwoka commented Mar 12, 2025

Guess I got a style thing to fix ☢️

@chrmarti
Copy link
Contributor

CI doesn't seem to pick up the latest commit. Will close and reopen to trigger fresh.

Copy link
Contributor

@chrmarti chrmarti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that run-user-commands, read-configuration and exec can be run without a workspace folder. This is to support attaching to an existing container that was not created with up. Making the cwd the workspace folder breaks this case.

For these commands maybe the cwd can be the default when none of --container-id, --id-label or --workspace-folder are given.

What do you think?

@@ -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' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, run-user-commands can be run without a workspace folder when attaching to an existing container that is not based on a workspace with a devcontainer.json.

For compatibility it might make sense to keep the existing behavior.

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

@@ -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']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as with run-user-commands, read-configuration can be run without workspace folder.

@@ -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']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants