From fe873182549464ed77fe90562bc3614489074ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Fri, 1 Feb 2019 00:52:57 +0100 Subject: [PATCH] Move buckets functions from lib-exec into lib --- lib/buckets.ps1 | 49 ++++++++++++++++++++++++++++++++++++++++ libexec/scoop-bucket.ps1 | 49 ---------------------------------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/lib/buckets.ps1 b/lib/buckets.ps1 index 94caec30bd..e9abd8b9cb 100644 --- a/lib/buckets.ps1 +++ b/lib/buckets.ps1 @@ -57,6 +57,55 @@ function find_manifest($app, $bucket) { } } +function add_bucket($name, $repo) { + if(!$name) { " missing"; $usage_add; exit 1 } + if(!$repo) { + $repo = known_bucket_repo $name + if(!$repo) { "Unknown bucket '$name'. Try specifying ."; $usage_add; exit 1 } + } + + $git = try { Get-Command 'git' -ea stop } catch { $null } + if(!$git) { + abort "Git is required for buckets. Run 'scoop install git'." + } + + $dir = bucketdir $name + if(test-path $dir) { + warn "The '$name' bucket already exists. Use 'scoop bucket rm $name' to remove it." + exit 0 + } + + write-host 'Checking repo... ' -nonewline + $out = git_ls_remote $repo 2>&1 + if($lastexitcode -ne 0) { + abort "'$repo' doesn't look like a valid git repository`n`nError given:`n$out" + } + write-host 'ok' + + ensure $bucketsdir > $null + $dir = ensure $dir + git_clone "$repo" "`"$dir`"" -q + success "The $name bucket was added successfully." +} + +function rm_bucket($name) { + if(!$name) { " missing"; $usage_rm; exit 1 } + $dir = bucketdir $name + if(!(test-path $dir)) { + abort "'$name' bucket not found." + } + + Remove-Item $dir -r -force -ea stop +} + +function list_buckets { + buckets +} + +function known_buckets { + known_bucket_repos | ForEach-Object { $_.psobject.properties | Select-Object -expand 'name' } +} + function new_issue_msg($app, $bucket, $title, $body) { $app, $manifest, $bucket, $url = locate $app $bucket $url = known_bucket_repo $bucket diff --git a/libexec/scoop-bucket.ps1 b/libexec/scoop-bucket.ps1 index a6fd8c922d..37635753c2 100644 --- a/libexec/scoop-bucket.ps1 +++ b/libexec/scoop-bucket.ps1 @@ -29,55 +29,6 @@ reset_aliases $usage_add = "usage: scoop bucket add []" $usage_rm = "usage: scoop bucket rm " -function add_bucket($name, $repo) { - if(!$name) { " missing"; $usage_add; exit 1 } - if(!$repo) { - $repo = known_bucket_repo $name - if(!$repo) { "Unknown bucket '$name'. Try specifying ."; $usage_add; exit 1 } - } - - $git = try { Get-Command 'git' -ea stop } catch { $null } - if(!$git) { - abort "Git is required for buckets. Run 'scoop install git'." - } - - $dir = bucketdir $name - if(test-path $dir) { - warn "The '$name' bucket already exists. Use 'scoop bucket rm $name' to remove it." - exit 0 - } - - write-host 'Checking repo... ' -nonewline - $out = git_ls_remote $repo 2>&1 - if($lastexitcode -ne 0) { - abort "'$repo' doesn't look like a valid git repository`n`nError given:`n$out" - } - write-host 'ok' - - ensure $bucketsdir > $null - $dir = ensure $dir - git_clone "$repo" "`"$dir`"" -q - success "The $name bucket was added successfully." -} - -function rm_bucket($name) { - if(!$name) { " missing"; $usage_rm; exit 1 } - $dir = bucketdir $name - if(!(test-path $dir)) { - abort "'$name' bucket not found." - } - - Remove-Item $dir -r -force -ea stop -} - -function list_buckets { - buckets -} - -function known_buckets { - known_bucket_repos | ForEach-Object { $_.psobject.properties | Select-Object -expand 'name' } -} - switch($cmd) { "add" { add_bucket $name $repo } "rm" { rm_bucket $name }