Skip to content

Commit

Permalink
Merge pull request #708 from bbenoist/feature/nuget-in-path
Browse files Browse the repository at this point in the history
feature/nuget-in-path: Also search for the NuGet executable in the PATH
  • Loading branch information
forki committed Mar 24, 2015
2 parents 2c29a41 + f83255d commit 1484d4f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/app/FakeLib/EnvironmentHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ let environVarOrNone name =
if String.IsNullOrEmpty var then None
else Some var

/// Splits the entries of an environment variable and removes the empty ones.
let splitEnvironVar name =
let var = environVarOrNone name
if var = None then [ ]
else var.Value.Split([| Path.PathSeparator |]) |> Array.toList

/// Retrieves the application settings variable with the given name
let appSetting (name : string) = ConfigurationManager.AppSettings.[name]

Expand Down
6 changes: 6 additions & 0 deletions src/app/FakeLib/FileSystemHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ let isDirectory path =

/// Detects whether the given path is a file.
let isFile path = isDirectory path |> not

/// Detects whether the given path does not contains invalid characters.
let isValidPath (path:string) =
Path.GetInvalidPathChars()
|> Array.filter (fun char -> path.Contains(char.ToString()))
|> Array.isEmpty
11 changes: 9 additions & 2 deletions src/app/FakeLib/ProcessHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ let ExecProcessElevated cmd args timeOut =
si.FileName <- cmd
si.UseShellExecute <- true) timeOut

/// Gets the list of valid directories included in the PATH environment variable.
let pathDirectories =
splitEnvironVar "PATH"
|> Seq.map (fun value -> value.Trim())
|> Seq.filter (fun value -> not <| isNullOrEmpty value)
|> Seq.filter isValidPath

/// Sets the environment Settings for the given startInfo.
/// Existing values will be overriden.
/// [omit]
Expand Down Expand Up @@ -339,8 +346,8 @@ let findFile dirs file =
/// ## Parameters
/// - `file` - The file to locate
let tryFindFileOnPath (file : string) : string option =
Environment.GetEnvironmentVariable("PATH").Split([| Path.PathSeparator |])
|> Seq.append ["."]
pathDirectories
|> Seq.append [ "." ]
|> fun path -> tryFindFile path file

/// Returns the AppSettings for the key - Splitted on ;
Expand Down
1 change: 1 addition & 0 deletions src/app/FakeLib/RestorePackageHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let findNuget defaultPath =
currentDirectory @@ ".nuget"
currentDirectory @@ "packages" @@ "NuGet.Commandline" @@ "tools"
currentDirectory @@ "packages" @@ "Nuget.Commandline" @@ "tools"]
|> Seq.append pathDirectories

let exeNames = ["nuget.exe"; "NuGet.exe"; "Nuget.exe"]

Expand Down

0 comments on commit 1484d4f

Please sign in to comment.