Skip to content

Commit

Permalink
return a boolean from nupm-home-prompt and early exit (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakub Žádník <[email protected]>
  • Loading branch information
amtoine and kubouch authored Oct 30, 2023
1 parent 80b9076 commit 61fb9cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion nupm/install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export def main [
--path # Install package from a directory with package.nuon given by 'name'
--force(-f) # Overwrite already installed package
]: nothing -> nothing {
nupm-home-prompt
if not (nupm-home-prompt) {
return
}

if not $path {
throw-error "missing_required_option" "`nupm install` currently requires a `--path` flag"
Expand Down
10 changes: 7 additions & 3 deletions nupm/utils/dirs.nu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const DEFAULT_NUPM_HOME = ($nu.default-config-dir | path join "nupm")
export const DEFAULT_NUPM_TEMP = ($nu.temp-path | path join "nupm")

# Prompt to create $env.NUPM_HOME if it does not exist and some sanity checks.
export def nupm-home-prompt [] {
#
# returns true if the root directory exists or has been created, false otherwise
export def nupm-home-prompt []: nothing -> bool {
if 'NUPM_HOME' not-in $env {
error make --unspanned {
msg: "Internal error: NUPM_HOME environment variable is not set"
Expand All @@ -23,7 +25,7 @@ export def nupm-home-prompt [] {
}
}

return
return true
}

mut answer = ''
Expand All @@ -35,10 +37,12 @@ export def nupm-home-prompt [] {
}

if ($answer | str downcase) != 'y' {
return
return false
}

mkdir $env.NUPM_HOME

true
}

export def script-dir [--ensure]: nothing -> path {
Expand Down

0 comments on commit 61fb9cc

Please sign in to comment.