mirror of
https://github.com/Smaug123/WoofWare.Whippet
synced 2025-10-07 08:48:40 +00:00
First release (#10)
Some checks are pending
.NET / build (Debug) (push) Waiting to run
.NET / build (Release) (push) Waiting to run
.NET / analyzers (push) Waiting to run
.NET / check-dotnet-format (push) Waiting to run
.NET / check-nix-format (push) Waiting to run
.NET / Check links (push) Waiting to run
.NET / Check flake (push) Waiting to run
.NET / nuget-pack (push) Waiting to run
.NET / expected-pack (push) Blocked by required conditions
.NET / check-accurate-generations (push) Waiting to run
.NET / all-required-checks-complete (push) Blocked by required conditions
.NET / nuget-publish (push) Blocked by required conditions
.NET / nuget-publish-fantomas (push) Blocked by required conditions
.NET / nuget-publish-json-plugin (push) Blocked by required conditions
.NET / nuget-publish-json-attrs (push) Blocked by required conditions
.NET / nuget-publish-argparser-plugin (push) Blocked by required conditions
.NET / nuget-publish-argparser-attrs (push) Blocked by required conditions
Some checks are pending
.NET / build (Debug) (push) Waiting to run
.NET / build (Release) (push) Waiting to run
.NET / analyzers (push) Waiting to run
.NET / check-dotnet-format (push) Waiting to run
.NET / check-nix-format (push) Waiting to run
.NET / Check links (push) Waiting to run
.NET / Check flake (push) Waiting to run
.NET / nuget-pack (push) Waiting to run
.NET / expected-pack (push) Blocked by required conditions
.NET / check-accurate-generations (push) Waiting to run
.NET / all-required-checks-complete (push) Blocked by required conditions
.NET / nuget-publish (push) Blocked by required conditions
.NET / nuget-publish-fantomas (push) Blocked by required conditions
.NET / nuget-publish-json-plugin (push) Blocked by required conditions
.NET / nuget-publish-json-attrs (push) Blocked by required conditions
.NET / nuget-publish-argparser-plugin (push) Blocked by required conditions
.NET / nuget-publish-argparser-attrs (push) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
namespace WoofWare.Whippet.Plugin.ArgParser
|
||||
|
||||
open System
|
||||
|
||||
/// Attribute indicating a record type to which the "build arg parser" Whippet generator should apply during build.
|
||||
///
|
||||
/// If you supply isExtensionMethod = false, you will get a module rather than extension methods.
|
||||
/// These can only be consumed from F#, but the benefit is that they don't use up the module name
|
||||
/// (since by default we create a module called "{TypeName}").
|
||||
type ArgParserAttribute (isExtensionMethod : bool) =
|
||||
inherit Attribute ()
|
||||
|
||||
/// The default value of `isExtensionMethod`, the optional argument to the ArgParserAttribute constructor.
|
||||
static member DefaultIsExtensionMethod = true
|
||||
|
||||
/// Shorthand for the "isExtensionMethod = false" constructor; see documentation there for details.
|
||||
new () = ArgParserAttribute ArgParserAttribute.DefaultIsExtensionMethod
|
||||
|
||||
/// Attribute indicating that this field shall accumulate all unmatched args,
|
||||
/// as well as any that appear after a bare `--`.
|
||||
///
|
||||
/// Set `includeFlagLike = true` to include args that begin `--` in the
|
||||
/// positional args.
|
||||
/// (By default, `includeFlagLike = false` and we throw when encountering
|
||||
/// an argument which looks like a flag but which we don't recognise.)
|
||||
/// We will still interpret `--help` as requesting help, unless it comes after
|
||||
/// a standalone `--` separator.
|
||||
type PositionalArgsAttribute (includeFlagLike : bool) =
|
||||
inherit Attribute ()
|
||||
|
||||
/// The default value of `isExtensionMethod`, the optional argument to the ArgParserAttribute constructor.
|
||||
static member DefaultIncludeFlagLike = false
|
||||
|
||||
/// Shorthand for the "includeFlagLike = false" constructor; see documentation there for details.
|
||||
new () = PositionalArgsAttribute PositionalArgsAttribute.DefaultIncludeFlagLike
|
||||
|
||||
/// Attribute indicating that this field shall have a default value derived
|
||||
/// from calling an appropriately named static method on the type.
|
||||
///
|
||||
/// This attribute can only be placed on fields of type `Choice<_, _>` where both type parameters
|
||||
/// are the same.
|
||||
/// After a successful parse, the value is Choice1Of2 if the user supplied an input,
|
||||
/// or Choice2Of2 if the input was obtained by calling the default function.
|
||||
///
|
||||
/// The static method we call for field `FieldName : 'a` is `DefaultFieldName : unit -> 'a`.
|
||||
type ArgumentDefaultFunctionAttribute () =
|
||||
inherit Attribute ()
|
||||
|
||||
/// Attribute indicating that this field shall have a default value derived
|
||||
/// from an environment variable (whose name you give in the attribute constructor).
|
||||
///
|
||||
/// This attribute can only be placed on fields of type `Choice<_, _>` where both type parameters
|
||||
/// are the same.
|
||||
/// After a successful parse, the value is Choice1Of2 if the user supplied an input,
|
||||
/// or Choice2Of2 if the input was obtained by pulling a value from `Environment.GetEnvironmentVariable`.
|
||||
type ArgumentDefaultEnvironmentVariableAttribute (envVar : string) =
|
||||
inherit Attribute ()
|
||||
|
||||
/// Attribute indicating that this field shall have the given help text, when `--help` is invoked
|
||||
/// or when a parse error causes us to print help text.
|
||||
type ArgumentHelpTextAttribute (helpText : string) =
|
||||
inherit Attribute ()
|
||||
|
||||
/// Attribute indicating that this field should be parsed with a ParseExact method on its type.
|
||||
/// For example, on a TimeSpan field, with [<ArgumentParseExact @"hh\:mm\:ss">], we will call
|
||||
/// `TimeSpan.ParseExact (s, @"hh\:mm\:ss", CultureInfo.CurrentCulture).
|
||||
type ParseExactAttribute (format : string) =
|
||||
inherit Attribute ()
|
||||
|
||||
/// Attribute indicating that this field should be parsed in the invariant culture, rather than the
|
||||
/// default current culture.
|
||||
/// For example, on a TimeSpan field, with [<InvariantCulture>] and [<ArgumentParseExact @"hh\:mm\:ss">], we will call
|
||||
/// `TimeSpan.ParseExact (s, @"hh\:mm\:ss", CultureInfo.InvariantCulture).
|
||||
type InvariantCultureAttribute () =
|
||||
inherit Attribute ()
|
||||
|
||||
/// Attribute placed on a field of a two-case no-data discriminated union, indicating that this is "basically a bool".
|
||||
/// For example: `type DryRun = | [<ArgumentFlag true>] Dry | [<ArgumentFlag false>] Wet`
|
||||
/// A record with `{ DryRun : DryRun }` will then be parsed like `{ DryRun : bool }` (so the user supplies `--dry-run`),
|
||||
/// but that you get this strongly-typed value directly in the code (so you `match args.DryRun with | DryRun.Dry ...`).
|
||||
///
|
||||
/// You must put this attribute on both cases of the discriminated union, with opposite values in each case.
|
||||
type ArgumentFlagAttribute (flagValue : bool) =
|
||||
inherit Attribute ()
|
||||
|
||||
/// Attribute placed on a field of a record to specify a different long form from the default. If you place this
|
||||
/// attribute, you won't get the default: ArgFoo would normally be expressed as `--arg-foo`, but if you instead
|
||||
/// say `[<ArgumentLongForm "thingy-blah">]` or `[<ArgumentLongForm "thingy">]`, you instead use `--thingy-blah`
|
||||
/// or `--thingy` respectively.
|
||||
///
|
||||
/// You can place this argument multiple times.
|
||||
///
|
||||
/// Omit the initial `--` that you expect the user to type.
|
||||
[<AttributeUsage(AttributeTargets.Field, AllowMultiple = true)>]
|
||||
type ArgumentLongForm (s : string) =
|
||||
inherit Attribute ()
|
@@ -0,0 +1,5 @@
|
||||
# WoofWare.Whippet.Plugin.ArgParser.Attributes
|
||||
|
||||
This is a very slim runtime dependency we expect consumers of WoofWare.Whippet.Plugin.ArgParser to take.
|
||||
This dependency contains attributes which control that source generator.
|
||||
Please see WoofWare.Whippet.Plugin.ArgParser's README for further information.
|
@@ -0,0 +1,24 @@
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgParserAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgParserAttribute..ctor [constructor]: bool
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgParserAttribute..ctor [constructor]: unit
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgParserAttribute.DefaultIsExtensionMethod [static property]: [read-only] bool
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgParserAttribute.get_DefaultIsExtensionMethod [static method]: unit -> bool
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentDefaultEnvironmentVariableAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentDefaultEnvironmentVariableAttribute..ctor [constructor]: string
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentDefaultFunctionAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentDefaultFunctionAttribute..ctor [constructor]: unit
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentFlagAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentFlagAttribute..ctor [constructor]: bool
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentHelpTextAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentHelpTextAttribute..ctor [constructor]: string
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentLongForm inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ArgumentLongForm..ctor [constructor]: string
|
||||
WoofWare.Whippet.Plugin.ArgParser.InvariantCultureAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.InvariantCultureAttribute..ctor [constructor]: unit
|
||||
WoofWare.Whippet.Plugin.ArgParser.ParseExactAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.ParseExactAttribute..ctor [constructor]: string
|
||||
WoofWare.Whippet.Plugin.ArgParser.PositionalArgsAttribute inherit System.Attribute
|
||||
WoofWare.Whippet.Plugin.ArgParser.PositionalArgsAttribute..ctor [constructor]: bool
|
||||
WoofWare.Whippet.Plugin.ArgParser.PositionalArgsAttribute..ctor [constructor]: unit
|
||||
WoofWare.Whippet.Plugin.ArgParser.PositionalArgsAttribute.DefaultIncludeFlagLike [static property]: [read-only] bool
|
||||
WoofWare.Whippet.Plugin.ArgParser.PositionalArgsAttribute.get_DefaultIncludeFlagLike [static method]: unit -> bool
|
@@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Authors>Patrick Stevens</Authors>
|
||||
<Copyright>Copyright (c) Patrick Stevens 2024</Copyright>
|
||||
<Description>Attributes to accompany the WoofWare.Whippet.Plugin.ArgParser source generator, to indicate what you want your types to be doing.</Description>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/Smaug123/WoofWare.Whippet</RepositoryUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageTags>fsharp;source-generator;source-gen;whippet;arguments;arg-parser</PackageTags>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarnOn>FS3559</WarnOn>
|
||||
<PackageId>WoofWare.Whippet.Plugin.ArgParser.Attributes</PackageId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes.fs" />
|
||||
<EmbeddedResource Include="SurfaceBaseline.txt" />
|
||||
<EmbeddedResource Include="version.json" />
|
||||
<None Include="README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>/</PackagePath>
|
||||
<Link>README.md</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Update="FSharp.Core" Version="4.3.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2",
|
||||
"publicReleaseRefSpec": [
|
||||
"^refs/heads/main$"
|
||||
],
|
||||
"pathFilters": [
|
||||
"./",
|
||||
":/global.json",
|
||||
":/Directory.Build.props"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user