Skip to content
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

automatic lookup for workspace folder #425

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

Conversation

MunsMan
Copy link

@MunsMan MunsMan commented Feb 27, 2023

Fixes #29 by checking if the current working directory contains a .devcontainer folder.

I added this check after seeing #332

It looks like that the following two if-statements are obsolete.
If they are obsolete, just let me know, then I will remove them as well.

@sarashino
Copy link

sarashino commented Feb 28, 2023

I think better reopen this. or feel free to reuse my codes.
#387

@MunsMan
Copy link
Author

MunsMan commented Feb 28, 2023

@sarashino I just looked at your code and I agree that your isDirectory checks makes sense and I will add it.

Is DEVCONTAINERS_CEILING_DIRECTORIES part of the office spec? Couldn't find it anywhere. What is its purpose?

@sarashino
Copy link

@MunsMan Thanks.
CEILING comes from GIT_CEILING_DIRECTORIES.
Mine is almost same implementation as git has.

P.S. Just for quick reply cause I'm not in front of my desk right now.

@MunsMan
Copy link
Author

MunsMan commented Feb 28, 2023

@sarashino Thanks for the prompt Response.

I disagree with you about the need of such a feature. I would propose that if the user messes up the working directory, that he should be notified. Otherwise, we might start an unwanted devcontainer or worse.
Therefore, I would keep it simple and just check if the cwd contains the .devcontainer directory.

@MunsMan
Copy link
Author

MunsMan commented Feb 28, 2023

@microsoft-github-policy-service agree

@MunsMan
Copy link
Author

MunsMan commented Feb 28, 2023

I added this feature to:

  • devcontainer up
  • devcontainer run-user-command
  • devcontainer read-configuration
  • devcontainer exec

Should it be added to devcontainer build as well? Currently, for devcontainer build a workspace-path is required.

Had to add default to ensure that `workspace-folder` can't be undefined
@MunsMan
Copy link
Author

MunsMan commented Feb 28, 2023

Just added a draft for the devcontainer build command. I added the default option, to ensure for typescript that the workspace-folder is a string. I would love to hear about a different implementation approach.

Furthermore, I wondered if the path which should be specified for the build command is even used. Likewise, I could find any reason why it is specified in the docs. With the latest push, you can build with just devcontainer build if you are in your working folder.

@hpe-ykoehler
Copy link

This PR seems to have a great usability value, yet I am not seeing what is blocking this from getting merge, as an interested parties I would like to know and potentially help getting this merged.

Copy link
Member

@samruddhikhandale samruddhikhandale left a comment

Choose a reason for hiding this comment

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

Apologies for not reviewing this PR sooner. Left some comments.

@MunsMan are you still interested in contributing this PR? It would be awesome to merge this in. If so, can you add few tests to validate these changes? Thanks!

if (!(argv['workspace-folder'] || argv['override-config'])) {
throw new Error('Missing required argument: workspace-folder or override-config');
if (!(argv['id-label'] || argv['override-config'] || isWorkspaceFound)) {
throw new Error('Missing required argument: workspace-folder or id-label or override-config');
Copy link
Member

Choose a reason for hiding this comment

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

As workspace-folder is no longer a required parameter, this error message could be misleading. Instead can we give a similar error (eg. Dev container config not found.) 👇 if workspace is not found?

throw new ContainerError({ description: `Dev container config (${uriToFsPath(configFile, cliHost.platform)}) not found.` });

if (argv['workspace-folder'] === '.') {
const workspaceFolder = findWorkspaceFolder();
if (!workspaceFolder) {
throw new Error('Unable to find Configuration File, provide workspace-folder argument');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw new Error('Unable to find Configuration File, provide workspace-folder argument');
throw new Error('Unable to find the dev container config, provide workspace-folder argument');

@@ -696,17 +716,23 @@ function runUserCommandsOptions(y: Argv) {
})
.check(argv => {
const idLabels = (argv['id-label'] && (Array.isArray(argv['id-label']) ? argv['id-label'] : [argv['id-label']])) as string[] | undefined;
const isWorkspaceFound = argv['workspace-folder'] || findWorkspaceFolder();
console.debug(isWorkspaceFound);
Copy link
Member

Choose a reason for hiding this comment

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

nit: Should we remove this?

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean the debug log? I just removed it.
The isWorkspaceFound is required in a lower check, but I adjusted the Error Message there as well.

@MunsMan
Copy link
Author

MunsMan commented Sep 21, 2023

@samruddhikhandale I will take a look at it over the coming days. The Pull Request is that old, I barely remember the codebase.

@MunsMan
Copy link
Author

MunsMan commented Sep 22, 2023

@samruddhikhandale Do you have a proper styling sheet, or a method to style the code before committing?
My personal configuration doesn't match the original styles and using tsfmt doesn't help...

@@ -82,6 +83,16 @@ const mountRegex = /^type=(bind|volume),source=([^,]+),target=([^,]+)(?:,externa

})().catch(console.error);

function findWorkspaceFolder(): string | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be sufficient to just make . the default for --workspace-folder?

@kita99
Copy link

kita99 commented Mar 23, 2024

Hey guys, I'm really interested in getting this merged as I think it would greatly improve the CLI. In case @MunsMan has no time to pick this back up I volunteer to help get the feature merged.

Can one of the reviewers (@chrmarti, @samruddhikhandale) post a quick reply with the key points required to get this rolling again?

@MunsMan
Copy link
Author

MunsMan commented Mar 23, 2024

That would be great. I currently have no use for this and no capacity to write the tests. @kita99 If you can take over, that would be great.

@g-arjones
Copy link

I'm also willing to finish this up so it can get merged. @chrmarti @samruddhikhandale could one of you please summarize what's missing? It's currently the most up-voted feature request, there's a PR already open and more people willing to contribute. All we need is a reviewer, please.

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.

Why Is --workspace-folder Required. Can we default to $PWD?
7 participants