Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@echo off
cls

dotnet run --project ./build/Build.fsproj %*
5 changes: 3 additions & 2 deletions build/PackageTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ let publishBinaryInPath (path : string) (version : string) (versionSuffix : stri
"Platform", runtime.GetPlatform()
"PublishSingleFile", "true"
]
}
}
DisableInternalBinLog = true
}
}
)

let publishBinary (version : string) (versionSuffix : string Option) (runtime : RunTime) =
Expand Down
37 changes: 27 additions & 10 deletions src/ArcCommander/APIs/ArcAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,44 @@ module API =
/// ArcCommander API functions that get executed by top level subcommand verbs.
module ArcAPI =

/// Gets the ArcCommander's current version and displays it.
let version _ =

let log = Logging.createLogger "ArcVersionLog"

log.Info($"Start Arc Version")
log.Info("Start Arc Version")

let assembly = Reflection.Assembly.GetExecutingAssembly()

let productVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion

if productVersion.Contains "-" then
log.Debug($"v{productVersion}")
else
let fv = assembly.GetName().Version
log.Debug($"v{fv.Major}.{fv.Minor}.{fv.Build}")


/// Displays test messages at different log levels.
let testMessage _ =

let log = Logging.createLogger "ArcTestMessageLog"

//log.Info("Start Arc TestMessage")

log.Info("This is an Info message")
log.Trace("This is a Trace message")
log.Debug("This is a Debug message")
log.Warn("This is a Warning message")
log.Error("This is an Error message")
log.Fatal("This is a Fatal Error message")


/// Initializes the ARC-specific folder structure.
let init (arcConfiguration : ArcConfiguration) (arcArgs : ArcParseResults<ArcInitArgs>) =

let log = Logging.createLogger "ArcInitLog"

log.Info("Start Arc Init")

let workDir = GeneralConfiguration.getWorkDirectory arcConfiguration
Expand All @@ -64,9 +81,9 @@ module ArcAPI =
let gitLFSThreshold = arcArgs.TryGetFieldValue ArcInitArgs.GitLFSByteThreshold
let branch = arcArgs.TryGetFieldValue ArcInitArgs.Branch |> Option.defaultValue GitHelper.defaultBranch
let repositoryAddress = arcArgs.TryGetFieldValue ArcInitArgs.RepositoryAddress
let identifier =
let identifier =
arcArgs.TryGetFieldValue ArcInitArgs.InvestigationIdentifier
|> Option.defaultValue (DirectoryInfo(workDir).Name)
|> Option.defaultValue (DirectoryInfo(workDir).Name)

log.Trace("Create Directory")

Expand All @@ -75,15 +92,15 @@ module ArcAPI =
log.Trace("Initiate folder structure")

let isa = ArcInvestigation.create(identifier)
ARC(isa).Write(arcConfiguration)
ARC(isa).Write(arcConfiguration)

GeneralConfiguration.tryGetRootfolder arcConfiguration
|> Option.iter (fun p ->
let dir = Path.Combine(workDir,p)
Directory.CreateDirectory dir |> ignore
let p = Path.Combine(dir,".gitkeep")
File.WriteAllText(p,"")
)
)

log.Trace("Set configuration")

Expand Down
4 changes: 3 additions & 1 deletion src/ArcCommander/Commands/ArcCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open ArcCommander.CLIArguments
[<HelpFlags([|"--help"; "-h"|])>]
type ArcCommand =
///Parameters
| [<AltCommandLine("-p")>][<Unique>] WorkingDir of working_directory : string
| [<AltCommandLine("-p")>][<Unique>] WorkingDir of working_directory : string
| [<AltCommandLine("-v")>][<Unique>] Verbosity of verbosity : int
///Commands
| [<CliPrefix(CliPrefix.None)>] Init of init_args : ParseResults<ArcInitArgs>
Expand All @@ -17,6 +17,7 @@ type ArcCommand =
| [<CliPrefix(CliPrefix.None)>] Server of server_args : ParseResults<ArcServerArgs>
| [<CliPrefix(CliPrefix.None)>][<SubCommand()>] Update
| [<AltCommandLine("--version")>][<CliPrefix(CliPrefix.None)>][<SubCommand()>] Version
| [<AltCommandLine("--testmessage")>][<CliPrefix(CliPrefix.None)>][<SubCommand()>] TestMessage
///Subcommands
| [<AltCommandLine("i")>][<CliPrefix(CliPrefix.None)>] Investigation of verb_and_args : ParseResults<InvestigationCommand>
| [<AltCommandLine("s")>][<CliPrefix(CliPrefix.None)>] Study of verb_and_args : ParseResults<StudyCommand>
Expand All @@ -41,4 +42,5 @@ type ArcCommand =
| Assay _ -> "Assay functions"
| Configuration _ -> "Configuration editing"
| Version -> "Get the ArcCommander's current version"
| TestMessage -> "Display a test message to check for correct coloring"
| Server _ -> "Start the ArcCommander as a local server"
22 changes: 17 additions & 5 deletions src/ArcCommander/Logging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open NLog.Conditions
module Logging =

/// Generates an NLog config with `folderPath` being the output folder for the log file.
let generateConfig (folderPath : string) verbosity =
let generateConfig (folderPath : string) consoleColor verbosity =
// initialize base configuration class, can be modified
let config = new LoggingConfiguration()

Expand Down Expand Up @@ -48,6 +48,15 @@ module Logging =
config.AddTarget(fileTarget)

// define rules for colors that shall differ from the default color theme
let debugColorRule = new ConsoleRowHighlightingRule()
debugColorRule.Condition <- ConditionParser.ParseExpression("level == LogLevel.Debug")
debugColorRule.ForegroundColor <- ConsoleOutputColor.Black
let traceColorRule = new ConsoleRowHighlightingRule()
traceColorRule.Condition <- ConditionParser.ParseExpression("level == LogLevel.Trace")
traceColorRule.ForegroundColor <- ConsoleOutputColor.Black
let infoColorRule = new ConsoleRowHighlightingRule()
infoColorRule.Condition <- ConditionParser.ParseExpression("level == LogLevel.Info")
infoColorRule.ForegroundColor <- ConsoleOutputColor.Black
let warnColorRule = new ConsoleRowHighlightingRule()
warnColorRule.Condition <- ConditionParser.ParseExpression("level == LogLevel.Warn")
warnColorRule.ForegroundColor <- ConsoleOutputColor.Yellow
Expand All @@ -60,6 +69,9 @@ module Logging =
fatalColorRule.BackgroundColor <- ConsoleOutputColor.DarkYellow

// add the newly defined rules to the console target
consoleTarget1.RowHighlightingRules.Add(infoColorRule)
consoleTarget1.RowHighlightingRules.Add(traceColorRule)
consoleTarget1.RowHighlightingRules.Add(debugColorRule)
consoleTarget2.RowHighlightingRules.Add(errorColorRule)
consoleTarget2.RowHighlightingRules.Add(fatalColorRule)
consoleTarget3.RowHighlightingRules.Add(warnColorRule)
Expand All @@ -77,7 +89,7 @@ module Logging =
config.AddRuleForOneLevel(LogLevel.Error, fileTarget)
config.AddRuleForOneLevel(LogLevel.Fatal, consoleTarget2) // fatal errors shall be used for critical events that cause ArcCommander exceptions leading to an unsuccessful termination
config.AddRuleForOneLevel(LogLevel.Fatal, fileTarget) // impairing the ARC structure

// activate config for logger
LogManager.Configuration <- config

Expand All @@ -86,10 +98,10 @@ module Logging =
if output = null then ""
elif output.EndsWith('\n') then reviseOutput (output.[0 .. output.Length - 2])
else output

/// Checks if an error message coming from CMD not being able to call a program with the given name.
let matchCmdErrMsg (errMsg : string) = errMsg.Contains("is not recognized as an internal or external command")

/// Checks if an error message coming from Bash not being able to call a program with the given name.
let matchBashErrMsg (errMsg : string) = errMsg.Contains("bash: ") && errMsg.Contains("command not found") || errMsg.Contains("No such file or directory")

Expand Down Expand Up @@ -119,6 +131,6 @@ module Logging =
| true,false,false -> printfn "%s" exn.Message // exception message contains usage message but NO error message
| false,false,true -> () // empty error message
| _ -> log.Error(exn) // everything else will be a non-empty error message

/// Checks if a message (string) is empty and if it is not, applies a logging function to it.
let checkNonLog s (logging : string -> unit) = if s <> "" then logging s
15 changes: 9 additions & 6 deletions src/ArcCommander/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
| InvestigationCommand.Show -> processCommandWithoutArgs arcConfiguration InvestigationAPI.show

let handleStudySubCommands arcConfiguration studyVerb =
match studyVerb with

Check warning on line 161 in src/ArcCommander/Program.fs

View workflow job for this annotation

GitHub Actions / build-and-test-linux

Incomplete pattern matches on this expression. For example, the value 'Rename (_)' may indicate a case not covered by the pattern(s).

Check warning on line 161 in src/ArcCommander/Program.fs

View workflow job for this annotation

GitHub Actions / build-and-test-windows

Incomplete pattern matches on this expression. For example, the value 'Rename (_)' may indicate a case not covered by the pattern(s).
| StudyCommand.Init r -> processCommand arcConfiguration StudyAPI.init r
| StudyCommand.Register r -> processCommand arcConfiguration StudyAPI.register r
| StudyCommand.Add r -> processCommand arcConfiguration StudyAPI.add r
Expand All @@ -176,7 +176,7 @@
//| StudyCommand.Protocol subCommand -> handleStudyProtocolSubCommands arcConfiguration (subCommand.GetSubCommand())

let handleAssaySubCommands arcConfiguration assayVerb =
match assayVerb with

Check warning on line 179 in src/ArcCommander/Program.fs

View workflow job for this annotation

GitHub Actions / build-and-test-linux

Incomplete pattern matches on this expression. For example, the value 'Rename (_)' may indicate a case not covered by the pattern(s).

Check warning on line 179 in src/ArcCommander/Program.fs

View workflow job for this annotation

GitHub Actions / build-and-test-windows

Incomplete pattern matches on this expression. For example, the value 'Rename (_)' may indicate a case not covered by the pattern(s).
| AssayCommand.Init r -> processCommand arcConfiguration AssayAPI.init r
| AssayCommand.Register r -> processCommand arcConfiguration AssayAPI.register r
| AssayCommand.Add r -> processCommand arcConfiguration AssayAPI.add r
Expand Down Expand Up @@ -218,6 +218,7 @@
| Server r -> processCommand arcConfiguration Server.start r
| Update -> processCommandWithoutArgs arcConfiguration ArcAPI.update
| Version -> processCommandWithoutArgs arcConfiguration ArcAPI.version
| TestMessage -> processCommandWithoutArgs arcConfiguration ArcAPI.testMessage
// Git Verbs
| Sync r -> processCommand arcConfiguration GitAPI.sync r
| Get r -> processCommand arcConfiguration GitAPI.get r
Expand All @@ -228,9 +229,11 @@
[<EntryPoint>]
let main argv =

let consoleBgColor = Console.BackgroundColor

try
let parser = ArgumentParser.Create<ArcCommand>(checkStructure = false)

// Failsafe parsing of all correct argument information
let safeParseResults = parser.ParseCommandLine(inputs = argv, ignoreMissing = true, ignoreUnrecognized = true)

Expand All @@ -251,12 +254,12 @@
|> IniData.fromNameValuePairs
|> ArcConfiguration.load
// <-----

let arcCommanderDataFolder = IniData.createDataFolder ()
let arcDataFolder =
tryGetArcDataFolderPath workingDir arcCommanderDataFolder
|> Option.defaultValue arcCommanderDataFolder
Logging.generateConfig arcDataFolder (GeneralConfiguration.getVerbosity arcConfiguration)
Logging.generateConfig arcDataFolder consoleBgColor (GeneralConfiguration.getVerbosity arcConfiguration)
let log = Logging.createLogger "ArcCommanderMainLog"

log.Trace("Start ArcCommander")
Expand All @@ -279,7 +282,7 @@
1

with e1 ->

let currDir = Directory.GetCurrentDirectory()

// check for existence of an ARC-specific log file:
Expand All @@ -288,13 +291,13 @@
let arcDataFolder =
tryGetArcDataFolderPath currDir arcCommanderDataFolder
|> Option.defaultValue arcCommanderDataFolder
Logging.generateConfig arcDataFolder 0
Logging.generateConfig arcDataFolder consoleBgColor 0

// create logging config, create .arc folder if not already existing:
with _ ->
let arcFolder = Path.Combine(currDir, ".arc")
Directory.CreateDirectory(arcFolder) |> ignore
Logging.generateConfig arcFolder 0
Logging.generateConfig arcFolder consoleBgColor 0

let log = Logging.createLogger "ArcCommanderMainLog"

Expand Down
Loading