Skip to content

Commit fe87318

Browse files
committed
Move buckets functions from lib-exec into lib
1 parent c00c0a1 commit fe87318

2 files changed

Lines changed: 49 additions & 49 deletions

File tree

lib/buckets.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,55 @@ function find_manifest($app, $bucket) {
5757
}
5858
}
5959

60+
function add_bucket($name, $repo) {
61+
if(!$name) { "<name> missing"; $usage_add; exit 1 }
62+
if(!$repo) {
63+
$repo = known_bucket_repo $name
64+
if(!$repo) { "Unknown bucket '$name'. Try specifying <repo>."; $usage_add; exit 1 }
65+
}
66+
67+
$git = try { Get-Command 'git' -ea stop } catch { $null }
68+
if(!$git) {
69+
abort "Git is required for buckets. Run 'scoop install git'."
70+
}
71+
72+
$dir = bucketdir $name
73+
if(test-path $dir) {
74+
warn "The '$name' bucket already exists. Use 'scoop bucket rm $name' to remove it."
75+
exit 0
76+
}
77+
78+
write-host 'Checking repo... ' -nonewline
79+
$out = git_ls_remote $repo 2>&1
80+
if($lastexitcode -ne 0) {
81+
abort "'$repo' doesn't look like a valid git repository`n`nError given:`n$out"
82+
}
83+
write-host 'ok'
84+
85+
ensure $bucketsdir > $null
86+
$dir = ensure $dir
87+
git_clone "$repo" "`"$dir`"" -q
88+
success "The $name bucket was added successfully."
89+
}
90+
91+
function rm_bucket($name) {
92+
if(!$name) { "<name> missing"; $usage_rm; exit 1 }
93+
$dir = bucketdir $name
94+
if(!(test-path $dir)) {
95+
abort "'$name' bucket not found."
96+
}
97+
98+
Remove-Item $dir -r -force -ea stop
99+
}
100+
101+
function list_buckets {
102+
buckets
103+
}
104+
105+
function known_buckets {
106+
known_bucket_repos | ForEach-Object { $_.psobject.properties | Select-Object -expand 'name' }
107+
}
108+
60109
function new_issue_msg($app, $bucket, $title, $body) {
61110
$app, $manifest, $bucket, $url = locate $app $bucket
62111
$url = known_bucket_repo $bucket

libexec/scoop-bucket.ps1

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,6 @@ reset_aliases
2929
$usage_add = "usage: scoop bucket add <name> [<repo>]"
3030
$usage_rm = "usage: scoop bucket rm <name>"
3131

32-
function add_bucket($name, $repo) {
33-
if(!$name) { "<name> missing"; $usage_add; exit 1 }
34-
if(!$repo) {
35-
$repo = known_bucket_repo $name
36-
if(!$repo) { "Unknown bucket '$name'. Try specifying <repo>."; $usage_add; exit 1 }
37-
}
38-
39-
$git = try { Get-Command 'git' -ea stop } catch { $null }
40-
if(!$git) {
41-
abort "Git is required for buckets. Run 'scoop install git'."
42-
}
43-
44-
$dir = bucketdir $name
45-
if(test-path $dir) {
46-
warn "The '$name' bucket already exists. Use 'scoop bucket rm $name' to remove it."
47-
exit 0
48-
}
49-
50-
write-host 'Checking repo... ' -nonewline
51-
$out = git_ls_remote $repo 2>&1
52-
if($lastexitcode -ne 0) {
53-
abort "'$repo' doesn't look like a valid git repository`n`nError given:`n$out"
54-
}
55-
write-host 'ok'
56-
57-
ensure $bucketsdir > $null
58-
$dir = ensure $dir
59-
git_clone "$repo" "`"$dir`"" -q
60-
success "The $name bucket was added successfully."
61-
}
62-
63-
function rm_bucket($name) {
64-
if(!$name) { "<name> missing"; $usage_rm; exit 1 }
65-
$dir = bucketdir $name
66-
if(!(test-path $dir)) {
67-
abort "'$name' bucket not found."
68-
}
69-
70-
Remove-Item $dir -r -force -ea stop
71-
}
72-
73-
function list_buckets {
74-
buckets
75-
}
76-
77-
function known_buckets {
78-
known_bucket_repos | ForEach-Object { $_.psobject.properties | Select-Object -expand 'name' }
79-
}
80-
8132
switch($cmd) {
8233
"add" { add_bucket $name $repo }
8334
"rm" { rm_bucket $name }

0 commit comments

Comments
 (0)