From 2d444993e7848aa1723e6273b855205d8fcaabf7 Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 26 Jan 2022 21:05:37 +1100 Subject: [PATCH] Added basic project infrastructure. --- Makefile | 27 +++++++++++++++++++++++ cli/Program.fs | 44 +++++++++++++++++++++++++++++++++++++ cli/cli.fsproj | 21 ++++++++++++++++++ git-guts/Library.fs | 4 ++++ git-guts/git-guts.fsproj | 13 +++++++++++ git-guts/tests/Program.fs | 1 + git-guts/tests/Tests.fs | 11 ++++++++++ git-guts/tests/tests.fsproj | 22 +++++++++++++++++++ 8 files changed, 143 insertions(+) create mode 100644 Makefile create mode 100644 cli/Program.fs create mode 100644 cli/cli.fsproj create mode 100644 git-guts/Library.fs create mode 100644 git-guts/git-guts.fsproj create mode 100644 git-guts/tests/Program.fs create mode 100644 git-guts/tests/Tests.fs create mode 100644 git-guts/tests/tests.fsproj diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..68ee432 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +PROJECTS=git-guts cli git-guts/tests + +build: + dotnet build --nologo --no-restore cli/cli.fsproj +build-tests: + dotnet build --nologo --no-restore git-guts/tests/tests.fsproj + +publish: + for proj in $(PROJECTS); do \ + rm -rf $$proj/bin/Release ; \ + rm -rf $$proj/obj/Release ; \ + done + dotnet publish --nologo --no-restore --configuration Release cli/cli.fsproj + +tests: + dotnet test --nologo --no-restore git-guts/tests/ + +clean: + for proj in $(PROJECTS); do \ + rm -rf $$proj/bin ; \ + rm -rf $$proj/obj ; \ + done + +restore: + for proj in $(PROJECTS); do \ + dotnet restore $$proj/*.fsproj ; \ + done diff --git a/cli/Program.fs b/cli/Program.fs new file mode 100644 index 0000000..69febb3 --- /dev/null +++ b/cli/Program.fs @@ -0,0 +1,44 @@ +open System +open System.IO +open Argu +open git_guts + +type CliArguments = + | [] Repo of path:string + interface IArgParserTemplate with + member s.Usage = + match s with + | Repo _ -> "specify the git repo directory." + +type CliExiter() = + interface IExiter with + member __.Name = "CliExiter" + member __.Exit( msg, code ) = + if code = ErrorCode.HelpText then + // show the help text + printfn "%s" msg + exit 0 + else + // show the error message (sans help text) + let pos = msg.IndexOf "USAGE:" + let msg2 = msg.Substring( 0, pos-1 ) + printfn "%s" msg2 + printfn "Use --help to get help." + exit 1 + +[] +let main argv = + + // parse the command-line arguments + let programName = System.AppDomain.CurrentDomain.FriendlyName + let parser = ArgumentParser.Create( programName=programName, helpTextMessage="Examine the guts of a git repo.", errorHandler=CliExiter() ) + let results = parser.Parse argv + let repoDir = Path.GetFullPath( results.GetResult( Repo, defaultValue="." ) ) + if not (Directory.Exists repoDir) then + failwith "Can't find git repo directory." + + // initialize + let gitGuts = GitGuts( repoDir ) + printfn "git guts: %A" gitGuts.repoDir + + 0 diff --git a/cli/cli.fsproj b/cli/cli.fsproj new file mode 100644 index 0000000..619f69d --- /dev/null +++ b/cli/cli.fsproj @@ -0,0 +1,21 @@ + + + + Exe + net5.0 + git_guts_cli + + + + + + + + + + + + + + + diff --git a/git-guts/Library.fs b/git-guts/Library.fs new file mode 100644 index 0000000..d2f93bb --- /dev/null +++ b/git-guts/Library.fs @@ -0,0 +1,4 @@ +namespace git_guts + +type GitGuts( repoDir: string ) = + member this.repoDir = repoDir diff --git a/git-guts/git-guts.fsproj b/git-guts/git-guts.fsproj new file mode 100644 index 0000000..ea175c7 --- /dev/null +++ b/git-guts/git-guts.fsproj @@ -0,0 +1,13 @@ + + + + net5.0 + git_guts + true + + + + + + + diff --git a/git-guts/tests/Program.fs b/git-guts/tests/Program.fs new file mode 100644 index 0000000..0695f84 --- /dev/null +++ b/git-guts/tests/Program.fs @@ -0,0 +1 @@ +module Program = let [] main _ = 0 diff --git a/git-guts/tests/Tests.fs b/git-guts/tests/Tests.fs new file mode 100644 index 0000000..b31d3c2 --- /dev/null +++ b/git-guts/tests/Tests.fs @@ -0,0 +1,11 @@ +namespace tests + +open System +open Microsoft.VisualStudio.TestTools.UnitTesting + +[] +type TestClass () = + + [] + member this.TestMethodPassing () = + Assert.IsTrue( true ) diff --git a/git-guts/tests/tests.fsproj b/git-guts/tests/tests.fsproj new file mode 100644 index 0000000..cccb7e6 --- /dev/null +++ b/git-guts/tests/tests.fsproj @@ -0,0 +1,22 @@ + + + + net5.0 + + false + false + + + + + + + + + + + + + + +