Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-ScriptDirectory {
- if (!$PSScriptRoot) {
- $Invocation = (Get-Variable MyInvocation -Scope 1).Value
- $PSScriptRoot = Split-Path $Invocation.MyCommand.Path
- }
- $PSScriptRoot
- }
- function Run-RubyCommand($command, $argList) {
- # Use the correct embedded ruby path. We'll be deployed at a path that looks like
- # [C:\opscode or some other prefix]\chef\modules\chef
- $ruby = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
- (Join-Path (Get-ScriptDirectory) "../../embedded/bin/ruby.exe")
- )
- $commandPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
- (Join-Path (Get-ScriptDirectory) "../../bin/$command")
- )
- # create list of process arguments by appending command arguments to ruby command path
- $commandArgumentList = @($commandPath) + @($argList)
- # splat argument list when invoking ruby
- & "$ruby" @commandArgumentList
- }
- function Invoke-ChefApply {
- Run-RubyCommand 'chef-apply' $args
- }
- Set-Alias -Name chef-apply -Value Invoke-ChefApply
- function Invoke-ChefClient {
- Run-RubyCommand 'chef-client' $args
- }
- Set-Alias -Name chef-client -Value Invoke-ChefClient
- function Invoke-ChefServiceManager {
- Run-RubyCommand 'chef-service-manager' $args
- }
- Set-Alias -Name chef-service-manager -Value Invoke-ChefServiceManager
- function Invoke-ChefShell {
- Run-RubyCommand 'chef-shell' $args
- }
- Set-Alias -Name chef-shell -Value Invoke-ChefShell
- function Invoke-ChefSolo {
- Run-RubyCommand 'chef-solo' $args
- }
- Set-Alias -Name chef-solo -Value Invoke-ChefSolo
- function Invoke-ChefWindowsService {
- Run-RubyCommand 'chef-windows-service' $args
- }
- Set-Alias -Name chef-windows-service -Value Invoke-ChefWindowsService
- function Invoke-Knife {
- Run-RubyCommand 'knife' $args
- }
- Set-Alias -Name knife -Value Invoke-Knife
- Export-ModuleMember -Function Invoke-ChefApply
- Export-ModuleMember -Alias chef-apply
- Export-ModuleMember -Function Invoke-ChefClient
- Export-ModuleMember -Alias chef-client
- Export-ModuleMember -Function Invoke-ChefServiceManager
- Export-ModuleMember -Alias chef-service-manager
- Export-ModuleMember -Function Invoke-ChefShell
- Export-ModuleMember -Alias chef-shell
- Export-ModuleMember -Function Invoke-ChefSolo
- Export-ModuleMember -Alias chef-solo
- Export-ModuleMember -Function Invoke-ChefWindowsService
- Export-ModuleMember -Alias chef-windows-service
- Export-ModuleMember -Function Invoke-Knife
- Export-ModuleMember -Alias knife
- # To debug this module, uncomment the line below
- # Export-ModuleMember -function Run-RubyCommand
- # Then run the following to reload the module. Use puts_argv as a helpful debug executable.
- # Remove-Module chef
- # Import-Module chef
- # "puts ARGV" | Out-File C:\opscode\chef\bin\puts_args -Encoding ASCII
- # Copy-Item C:\opscode\chef\bin\ohai.bat C:\opscode\chef\bin\puts_args.bat
- # Run-RubyCommand puts_args 'Here' "are" some '"very interesting"' 'arguments[to]' "`"try out`""
Add Comment
Please, Sign In to add comment