-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1978 from BlythMeister/fakeVarType
FakeVar enhancements
- Loading branch information
Showing
63 changed files
with
430 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Auto-Generated by FAKE; do not edit | ||
namespace System | ||
open System.Reflection | ||
|
||
[<assembly: AssemblyTitleAttribute("FAKE - F# Make Core FakeVar")>] | ||
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>] | ||
[<assembly: AssemblyVersionAttribute("5.0.0")>] | ||
[<assembly: AssemblyInformationalVersionAttribute("5.0.0.0")>] | ||
[<assembly: AssemblyFileVersionAttribute("5.0.0")>] | ||
do () | ||
|
||
module internal AssemblyVersionInformation = | ||
let [<Literal>] AssemblyTitle = "FAKE - F# Make Core FakeVar" | ||
let [<Literal>] AssemblyProduct = "FAKE - F# Make" | ||
let [<Literal>] AssemblyVersion = "5.0.0" | ||
let [<Literal>] AssemblyInformationalVersion = "5.0.0.0" | ||
let [<Literal>] AssemblyFileVersion = "5.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks> | ||
<AssemblyName>Fake.Core.FakeVar</AssemblyName> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="FakeVar.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Fake.Core.Context\Fake.Core.Context.fsproj" FromP2P="true" /> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/// This module contains helpers for managing build time variables | ||
[<RequireQualifiedAccess>] | ||
module Fake.Core.FakeVar | ||
|
||
open Fake.Core.Context | ||
|
||
/// Gets a strongly typed FakeVar by name returning an option type | ||
let get<'a> name = | ||
forceFakeContext() | ||
|> getFakeContext name | ||
|> Option.map (fun o -> try | ||
o :?> 'a | ||
with e -> | ||
raise <| exn(sprintf "Cast error on variable '%s'" name, e) | ||
) | ||
|
||
/// Gets a strongly typed FakeVar by name will fail if variable is not found | ||
let getOrFail<'a> name = | ||
match get<'a> name with | ||
| Some v -> v | ||
| _ -> failwithf "Unable to find variable '%s'" name | ||
|
||
/// Gets a strongly typed FakeVar by name will return default value if variable is not found | ||
let getOrDefault<'a> name defaultValue = | ||
match get<'a> name with | ||
| Some v -> v | ||
| _ -> defaultValue | ||
|
||
/// Removes a FakeVar by name | ||
let remove name = | ||
forceFakeContext() | ||
|> removeFakeContext name | ||
|> ignore | ||
|
||
/// Sets value of a FakeVar | ||
let set name (v:'a) = | ||
forceFakeContext() | ||
|> setFakeContext name v (fun _ -> v :> obj) | ||
|> ignore | ||
|
||
/// Define a named FakeVar providing the get, remove and set | ||
/// Will fail if there is no context | ||
let define<'a> name = | ||
if isFakeContext() then | ||
(fun () -> get name : 'a option), | ||
(fun () -> remove name), | ||
(fun (v : 'a) -> set name v) | ||
else | ||
failwithf "Cannot define variable '%s' without context" name | ||
|
||
/// Define a named FakeVar providing the get, remove and set | ||
/// Will create a local variable if there is no context | ||
let defineAllowNoContext<'a> name = | ||
if isFakeContext() then | ||
(fun () -> get name : 'a option), | ||
(fun () -> remove name), | ||
(fun (v : 'a) -> set name v) | ||
else | ||
let mutable varWithoutContext = None | ||
(fun () -> varWithoutContext), | ||
(fun () -> varWithoutContext <- None), | ||
(fun (v : 'a) -> varWithoutContext <- Some v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
group netcore | ||
|
||
FSharp.Core | ||
NETStandard.Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.