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

add a new --interactive switch to toolkit.nu run #112

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export def "install" [] {
# clean the environment before running the code
# > toolkit run --clean { gm clone https://github.com/amtoine/nu-git-manager --depth 1 }
export def "run" [
code: closure, # the code to run in the environment
code?: closure, # the code to run in the environment (required without `--interactive`)
--clean, # raise this to clean the environment before running the code
--interactive, # run interactively
] {
const GM_ENV = {
GIT_REPOS_HOME: ($nu.temp-path | path join "nu-git-manager/repos/"),
Expand All @@ -51,5 +52,26 @@ export def "run" [
}
}

with-env $GM_ENV $code
if $interactive {
const CONFIG_FILE = ($GM_ENV.GIT_REPOS_HOME | path dirname | path join "config.nu")
const ENV_FILE = ($GM_ENV.GIT_REPOS_HOME | path dirname | path join "env.nu")

"$env.config = {show_banner: false}" | save --force $CONFIG_FILE
"" | save --force $ENV_FILE

with-env ($GM_ENV | merge {PROMPT_COMMAND: "NU-GIT-MANAGER"}) {
^$nu.current-exe [
--env-config $ENV_FILE
--config $CONFIG_FILE
--execute "use ./src/nu-git-manager *"
]
}
} else {
if $code == null {
error make --unspanned {
msg: "`toolkit.nu run requires a `$code` when `--interactive` is not used"
}
}
with-env $GM_ENV $code
}
}