started on command dispatch

This commit is contained in:
Luke Sampson
2013-06-16 01:16:26 +10:00
parent 30c2d88876
commit 8ebddce654
8 changed files with 34 additions and 61 deletions
+2 -2
View File
@@ -3,9 +3,9 @@
$erroractionpreference='stop' # quit if anything goes wrong
# get core functions
$init_url = 'https://raw.github.com/lukesampson/scoop/master/lib/init.ps1'
$core_url = 'https://raw.github.com/lukesampson/scoop/master/lib/core.ps1'
echo 'initializing...'
iex (new-object net.webclient).downloadstring($init_url)
iex (new-object net.webclient).downloadstring($core_url)
# prep
assert_not_installed 'scoop'
+7 -2
View File
@@ -1,6 +1,11 @@
# Usage: sub <cmd>
param($cmd)
. "$(split-path $myinvocation.mycommand.path)\..\lib\init.ps1"
. "$(split-path $myinvocation.mycommand.path)\..\lib\core.ps1"
. (resolve '..\lib\commands')
require '..\lib\commands'
$commands = commands
if (@($null, '-h', '--help') -contains $cmd) { exec 'help' $args }
elseif ($commands -contains $cmd) { exec $cmd $args }
else { "scoop: '$cmd' isn't a scoop command. See 'scoop help'"; exit 1 }
+1 -1
View File
@@ -1,4 +1,4 @@
. "$(split-path $myinvocation.mycommand.path)\..\lib\init.ps1"
. "$(split-path $myinvocation.mycommand.path)\..\lib\core.ps1"
if(test-path $scoopdir) {
try {
+3
View File
@@ -0,0 +1,3 @@
# Usage: scoop help <cmd>
# Summary: show help for a command
echo "help!"
+3 -1
View File
@@ -1,2 +1,4 @@
# Usage: scoop install <name>
# Summary: Installs an app
# Summary: Installs an app
echo 'install!'
+8 -2
View File
@@ -1,3 +1,9 @@
function all_commands {
echo "all_commands"
function commands {
gci (resolve 'cmd') |
where { $_.name.endswith('.ps1') } |
% { ($_.name -replace '\.ps1$', '') }
}
function exec($cmd) {
& (resolve "cmd\$cmd.ps1")
}
+10 -5
View File
@@ -13,13 +13,13 @@ function appdir($name) { "$scoopdir\apps\$name" }
function fname($path) { split-path $path -leaf }
function ensure($dir) { if(!(test-path $dir)) { mkdir $dir > $null }; resolve-path $dir }
function full_path($path) {
function full_path($path) { # should be ~ rooted
$executionContext.sessionState.path.getUnresolvedProviderPathFromPSPath($path)
}
function friendly_path($path) {
return "$path" -replace ([regex]::escape($home)), "~"
}
function script_rel_path($path) { full_path "$($myInvocation.PSScriptRoot)\$path" }
function resolve($path) { "$($myInvocation.PSScriptRoot)\$path" } # relative to calling script
function installed($name) { return test-path (appdir $name) }
function assert_not_installed($name) {
@@ -51,7 +51,9 @@ function ensure_scoop_in_path {
}
}
$required = @( $myInvocation.myCommand.path.tolower )
# failed
<#
$required = @( $myInvocation.myCommand.path.tolower() )
function require($name) {
if(!$name.endsWith('.ps1')) { $name += '.ps1' }
$path = "$($myInvocation.PSScriptRoot)\$name"
@@ -59,6 +61,9 @@ function require($name) {
$path = "$(resolve-path $path)".tolower()
if(!($required -contains $path)) {
$required += $path
iex "$path"
#iex $path
#. $path -global
#import-module $path -global
}
}
}
#>
-48
View File
@@ -1,48 +0,0 @@
# 1. installs a powershell script to ~\appdata\local\scoop\[name]\[name].ps1
# 2. adds a stub to ~\appdata\local\scoop\bin, to avoid path pollution
# 3. makes sure ~\appdata\local\scoop\bin is in your path
function install-ps($name, $url) {
$erroractionpreference = 'stop'
# helpers
function dl($url,$to) { (new-object system.net.webClient).downloadFile($url,$to) }
function env($name,$val) {
if($val) { [environment]::setEnvironmentVariable($name,$val,'User') } # set
else { [environment]::getEnvironmentVariable($name, 'User') } # get
}
function abort($msg) { write-host $msg -b darkred -f white; exit 1 }
# prep
echo "installing $name..."
if($name.endswith(".ps1")) { $name = $name -replace '\.ps1$', '' }
$scoopdir = "~\appdata\local\scoop"
$bindir = "$scoopdir\bin"
$appdir = "$scoopdir\$name"
if(test-path $appdir) { abort("It looks like ``$name`` is already installed. If you'd like to re-install, please run ``rmdir ~\appdata\local\scoop\$name`` first.") }
# install
mkdir $appdir > $null
$appdir = resolve-path $appdir
echo "downloading $url..."
dl $url "$appdir\$name.ps1"
# binstub
echo "creating stub in ~\appdata\local\bin"
if(!(test-path $bindir)) { mkdir $bindir > $null }
$bindir = resolve-path $bindir
echo "`$rawargs = `$myInvocation.line -replace `"^`$([regex]::escape(`$myInvocation.invocationName))\s+`", `"`"" >> "$bindir\$name.ps1"
echo "iex `"$appdir\$name.ps1 `$rawargs`"" >> "$bindir\$name.ps1"
# ensure path
$userpath = env 'path'
if($userpath -notmatch [regex]::escape($bindir)) {
echo "adding ~\appdata\local\bin to your user path"
env 'path' "$userpath;$bindir" # for future sessions
$env:path = "$env:path;$bindir" # for this session
}
echo "done!"
}