2011-03-23 2 views
4

Gists from GitHub을 삽입하기 위해 NuGet package manager 콘솔에 대한 몇 가지 명령을 작성하고 싶습니다. 나는 4 기본 명령NuGet 패키지의 도우미 기능은 init.ps1이 전역 적이어야합니까?

  • 목록 - 기 스트 '사용자'
  • 요점-정보 'gistId'
  • 전시회 개요 - 내용 'gistId' 'fileName에'
  • Gist- 'gistId' 'fileName'

내 모든 명령 d 몇 가지 유틸리티 기능에 익숙해 져야하고, 글로벌이든 아니든간에 고민 중입니다.

# Json Parser 
function parseJson([string]$json, [bool]$throwError = $true) {  
    try { 
     $result = $serializer.DeserializeObject($json);  
     return $result; 
    } catch {     
     if($throwError) { throw "ERROR: Parsing Error"} 
     else { return $null }    
    } 
} 

function downloadString([string]$stringUrl) { 
    try {   
     return $webClient.DownloadString($stringUrl) 
    } catch {   
     throw "ERROR: Problem downloading from $stringUrl" 
    } 
} 

function parseUrl([string]$url) { 
    return parseJson(downloadString($url)); 
} 

난 그냥 내 전역 함수의 외부에서 이러한 유틸리티 기능을 가질 수, 또는 나는 어떻게 든 전역 함수 정의 범위의 각각에 포함해야합니까?

답변

6

아니요. init.sp1에서 작성한 powershell 모듈 (psm1)을 가져 와서 앞으로 진행하면 콘솔 환경에 메소드를 추가하는 것이 좋습니다.

param($installPath, $toolsPath) 
Import-Module (Join-Path $toolsPath MyModule.psm1) 

MyModule.psm1에서 :

귀하의 init.ps1는 다음과 같이 보일 것이다 당신은 여기에 모듈 http://msdn.microsoft.com/en-us/library/dd878340(v=VS.85).aspx

+0

좋은 대회에 대한 자세한 정보를 얻을 수 있습니다

function MyPrivateFunction { "Hello World" } function Get-Value { MyPrivateFunction } # Export only the Get-Value method from this module so that's what gets added to the nuget console environment Export-ModuleMember Get-Value 

, 그러나입니다 모듈 내에 정의 된 함수에서 $ toolsPath에 액세스하는 방법이 있습니까? – gerichhome