-
Notifications
You must be signed in to change notification settings - Fork 264
[shell] enable devbox add/rm to work for shells started in child directories #206
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ func generate(rootPath string, plan *plansdk.Plan, files []string) error { | |
outPath := filepath.Join(rootPath, ".devbox/gen") | ||
|
||
for _, file := range files { | ||
err := writeFromTemplate(outPath, plan, file) | ||
err := writeFromTemplate(outPath, plan, file, rootPath) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
@@ -36,7 +36,7 @@ func generate(rootPath string, plan *plansdk.Plan, files []string) error { | |
// Gitignore file is added to the .devbox directory | ||
// TODO savil. Remove this hardcode from here, so this function can be generically defined again | ||
// by accepting the files list parameter. | ||
err := writeFromTemplate(filepath.Join(rootPath, ".devbox"), plan, ".gitignore") | ||
err := writeFromTemplate(filepath.Join(rootPath, ".devbox"), plan, ".gitignore", rootPath) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
@@ -51,7 +51,7 @@ func generate(rootPath string, plan *plansdk.Plan, files []string) error { | |
return nil | ||
} | ||
|
||
func writeFromTemplate(path string, plan *plansdk.Plan, tmplName string) error { | ||
func writeFromTemplate(path string, plan *plansdk.Plan, tmplName string, rootPath string) error { | ||
embeddedPath := fmt.Sprintf("tmpl/%s.tmpl", tmplName) | ||
|
||
// Should we clear the directory so we start "fresh"? | ||
|
@@ -69,7 +69,7 @@ func writeFromTemplate(path string, plan *plansdk.Plan, tmplName string) error { | |
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
t := template.Must(template.New(tmplName+".tmpl").Funcs(templateFuncs).ParseFS(tmplFS, embeddedPath)) | ||
t := template.Must(template.New(tmplName+".tmpl").Funcs(templateFuncs(rootPath)).ParseFS(tmplFS, embeddedPath)) | ||
return errors.WithStack(t.Execute(f, plan)) | ||
} | ||
|
||
|
@@ -78,8 +78,12 @@ func toJSON(a any) string { | |
return string(data) | ||
} | ||
|
||
var templateFuncs = template.FuncMap{ | ||
"json": toJSON, | ||
"contains": strings.Contains, | ||
"debug": debug.IsEnabled, | ||
func templateFuncs(rootPath string) template.FuncMap { | ||
|
||
return template.FuncMap{ | ||
"json": toJSON, | ||
"contains": strings.Contains, | ||
"debug": debug.IsEnabled, | ||
"configDir": func() string { return rootPath }, | ||
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. Can we pass this in as part of the template data instead of a function? |
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ mkShell { | |
# exec a devbox shell. | ||
export IN_NIX_SHELL=0 | ||
export DEVBOX_SHELL_ENABLED=1 | ||
# Keep this env-var name same as boxcli.shellConfigEnvVar | ||
export DEVBOX_SHELL_CONFIG={{ configDir }} | ||
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. This needs to be quoted to handle spaces. |
||
|
||
# Undo the effects of `nix-shell --pure` on SSL certs. | ||
# See https://github.com/NixOS/nixpkgs/blob/dae204faa0243b4d0c0234a5f5f83a2549ecb5b7/pkgs/stdenv/generic/setup.sh#L677-L685 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I missed some of the discussion around this feature, so apologies if I'm rehashing some stuff.
I'm trying to think through what the expected behavior would be here.
I want to say that if we're adding this feature, then we should disallow setting the config flag when in a shell and print a warning when the env var is overriding another devbox.json. Also, if the path in the env var becomes invalid, then we should tell the user to restart their shell. Thoughts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh ho 🤦🏾 I was on auto-pilot and rebased this PR onto the
--config
flag parent PR, without thinking it through.With the new
--config
flag functionality, this PR is not needed! yay!You are totally right. Abandoning.