A deep dive into git internals.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
git-guts-fs/cli/Program.fs

74 lines
2.4 KiB

open System
open System.IO
open Spectre.Console
open Spectre.Console.Cli
open git_guts
// --------------------------------------------------------------------
let _getPackFilename packFilename repoDir =
if packFilename <> "" then
packFilename
else
// auto-detect pack files
let fnames = findRepoPacks repoDir
match fnames.Length with
| 0 -> failwith "No pack file was specified."
| 1 -> fnames.[0]
| _ -> failwith "Multiple pack files were found."
// --------------------------------------------------------------------
type AppSettings() =
inherit CommandSettings()
[<CommandOption( "-r|--repo <GIT-REPO>" )>]
member val RepoDir = "." with get, set
override this.Validate() =
this.RepoDir <- Path.GetFullPath( this.RepoDir )
if not ( Directory.Exists this.RepoDir ) then
ValidationResult.Error( "Can't find git repo directory." )
else
ValidationResult.Success()
// FUDGE! We need this for the settings in AppSettings to be recognized :-/
type AppCommand() =
inherit Command<AppSettings>()
override this.Execute( ctx, settings ) =
failwith "No command was specified."
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
type DumpPackFileSettings() =
inherit AppSettings()
[<CommandOption( "-f|--pack-file <PACK-FILE>" )>]
member val PackFilename = "" with get, set
type DumpPackFileCommand() =
inherit Command<DumpPackFileSettings>()
override this.Execute( ctx, settings ) =
let fname = _getPackFilename settings.PackFilename settings.RepoDir
dumpPackFile fname
0
// --------------------------------------------------------------------
[<EntryPoint>]
let main argv =
// Good grief! >:-/ Spectre.Console only checks for a NO_COLOR env var to see if it should disable
// colors (see ColorSystemDetector.Detect()), instead of checking if stdout is connected to a terminal,
// so we do that here.
if Console.IsOutputRedirected then
disableSpectreCapabilities
// parse the command-line arguments
let app = CommandApp<AppCommand>()
app.Configure( fun cfg ->
cfg.SetApplicationName( System.AppDomain.CurrentDomain.FriendlyName ) |> ignore
cfg.AddCommand<DumpPackFileCommand>( "dump-packfile" ).WithDescription(
"Dump a pack file."
) |> ignore
)
app.Run( argv )