forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 11
/
scoop-export.ps1
97 lines (85 loc) · 2.44 KB
/
scoop-export.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Usage: scoop export [<OPTIONS>]
# Summary: Export (an importable) list of installed applications.
#
# Options:
# -h, --help Show help for this command.
@(
@('core', 'Test-ScoopDebugEnabled'),
@('getopt', 'Resolve-GetOpt'),
@('help', 'scoop_help'),
@('Helpers', 'New-IssuePrompt'),
@('buckets', 'Get-KnownBucket'),
@('manifest', 'Resolve-ManifestInformation'),
@('Versions', 'Clear-InstalledVersion')
) | ForEach-Object {
if (!([bool] (Get-Command $_[1] -ErrorAction 'Ignore'))) {
Write-Verbose "Import of lib '$($_[0])' initiated from '$PSCommandPath'"
. (Join-Path $PSScriptRoot "..\lib\$($_[0]).ps1")
}
}
<#
TODO: Export:
{
"applications": [
{
"name": "xxx",
"version": "xxxx",
"bucket": "xxx",
"url": "xxx",
"architecture": "xxx",
"global": false|true,
"installedVersions": [
"xxx",
...
]
},
{...},
...
],
"buckets": [
{
"name": "xxx",
"url": "xxx"
}
],
"config": {
...wholeConfig
},
"aliases": {
"name": "xxx",
"body": [
"xxx"
]
},
environments??
}
#>
$ExitCode = 0
$Options, $null, $_err = Resolve-GetOpt $args
if ($_err) { Stop-ScoopExecution -Message "scoop export: $_err" -ExitCode 2 }
$local = installed_apps $false | ForEach-Object { @{ 'name' = $_; 'global' = $false } }
$global = installed_apps $true | ForEach-Object { @{ 'name' = $_; 'global' = $true } }
$Applications = @($local) + @($global)
# TODO: What to do?
if (!$Applications) { exit $ExitCode }
# Export applications
$Applications | Sort-Object -Property 'Name' | ForEach-Object {
$app = $_.name
$global = $_.global
$ver = Select-CurrentVersion -AppName $app -Global:$global
$globalDisplay = if ($global) { ' *global*' } else { $null }
$installInfo = install_info $app $ver $global
$bucket = ''
if ($installInfo.bucket) {
$bucket = ' [' + $installInfo.bucket + ']'
} elseif ($installInfo.url) {
$bucket = ' [' + $installInfo.url + ']'
}
if ($installInfo.architecture -and ((default_architecture) -ne $installInfo.architecture)) {
$arch = ' {' + $installInfo.architecture + '}'
} else {
$arch = ''
}
Write-UserMessage -Message "$app (v:$ver)$globalDisplay$bucket$arch" -Output
}
exit $ExitCode