Skip to content

Commit

Permalink
feat(install): Add arch support to env_add_path and env_set (Scoo…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsiao-nan Cheung authored and Richard Kuhnt committed Aug 26, 2019
1 parent f555968 commit c7d72d2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
16 changes: 14 additions & 2 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,25 @@ function strip_path($orig_path, $dir) {
return ($stripped -ne $orig_path), $stripped
}

function remove_from_path($dir,$global) {
function add_first_in_path($dir, $global) {
$dir = fullpath $dir

# future sessions
$null, $currpath = strip_path (env 'path' $global) $dir
env 'path' $global "$dir;$currpath"

# this session
$null, $env:PATH = strip_path $env:PATH $dir
$env:PATH = "$dir;$env:PATH"
}

function remove_from_path($dir, $global) {
$dir = fullpath $dir

# future sessions
$was_in_path, $newpath = strip_path (env 'path' $global) $dir
if($was_in_path) {
write-output "Removing $(friendly_path $dir) from your path."
Write-Output "Removing $(friendly_path $dir) from your path."
env 'path' $global $newpath
}

Expand Down
51 changes: 21 additions & 30 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru
create_startmenu_shortcuts $manifest $dir $global $architecture
install_psmodule $manifest $dir $global
if($global) { ensure_scoop_in_path $global } # can assume local scoop is in path
env_add_path $manifest $dir $global
env_set $manifest $dir $global
env_add_path $manifest $dir $global $architecture
env_set $manifest $dir $global $architecture

# persist data
persist_data $manifest $original_dir $persist_dir
Expand Down Expand Up @@ -931,54 +931,45 @@ function find_dir_or_subdir($path, $dir) {
return [string]::join(';', $fixed), $removed
}

function env_add_path($manifest, $dir, $global) {
$manifest.env_add_path | Where-Object { $_ } | ForEach-Object {
$path_dir = join-path $dir $_
function env_add_path($manifest, $dir, $global, $arch) {
$env_add_path = arch_specific 'env_add_path' $manifest $arch
$env_add_path | Where-Object { $_ } | ForEach-Object {
$path_dir = Join-Path $dir $_

if(!(is_in_dir $dir $path_dir)) {
if (!(is_in_dir $dir $path_dir)) {
abort "Error in manifest: env_add_path '$_' is outside the app directory."
}
add_first_in_path $path_dir $global
}
}

function add_first_in_path($dir, $global) {
$dir = fullpath $dir

# future sessions
$null, $currpath = strip_path (env 'path' $global) $dir
env 'path' $global "$dir;$currpath"

# this session
$null, $env:PATH = strip_path $env:PATH $dir
$env:PATH = "$dir;$env:PATH"
}

function env_rm_path($manifest, $dir, $global) {
# remove from path
$manifest.env_add_path | Where-Object { $_ } | ForEach-Object {
$path_dir = join-path $dir $_
function env_rm_path($manifest, $dir, $global, $arch) {
$env_add_path = arch_specific 'env_add_path' $manifest $arch
$env_add_path | Where-Object { $_ } | ForEach-Object {
$path_dir = Join-Path $dir $_

remove_from_path $path_dir $global
}
}

function env_set($manifest, $dir, $global) {
if($manifest.env_set) {
$manifest.env_set | Get-Member -member noteproperty | ForEach-Object {
function env_set($manifest, $dir, $global, $arch) {
$env_set = arch_specific 'env_set' $manifest $arch
if ($env_set) {
$env_set | Get-Member -Member NoteProperty | ForEach-Object {
$name = $_.name;
$val = format $manifest.env_set.$($_.name) @{ "dir" = $dir }
$val = format $env_set.$($_.name) @{ "dir" = $dir }
env $name $global $val
Set-Content env:\$name $val
}
}
}
function env_rm($manifest, $global) {
if($manifest.env_set) {
$manifest.env_set | Get-Member -member noteproperty | ForEach-Object {
function env_rm($manifest, $global, $arch) {
$env_set = arch_specific 'env_set' $manifest $arch
if ($env_set) {
$env_set | Get-Member -Member NoteProperty | ForEach-Object {
$name = $_.name
env $name $global $null
if(test-path env:\$name) { Remove-Item env:\$name }
if (Test-Path env:\$name) { Remove-Item env:\$name }
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
"checkver": {
"$ref": "#/definitions/checkver"
},
"env_add_path": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"env_set": {
"type": "object"
},
"extract_dir": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
Expand Down

0 comments on commit c7d72d2

Please sign in to comment.