summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-01 16:08:31 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-01 16:08:31 -0400
commit4675da0600edf6781cd740549ad0a175b606fc1e (patch)
tree0219cab065bfffbbbb9b048b6a30044f510be2c5
parentc023118356d9d7877dbdc9e88c4512fcdf33c256 (diff)
downloadSMAPI-4675da0600edf6781cd740549ad0a175b606fc1e.tar.gz
SMAPI-4675da0600edf6781cd740549ad0a175b606fc1e.tar.bz2
SMAPI-4675da0600edf6781cd740549ad0a175b606fc1e.zip
add --log-path argument to specify SMAPI log path during testing
-rw-r--r--README.md5
-rw-r--r--release-notes.md1
-rw-r--r--src/StardewModdingAPI/Constants.cs2
-rw-r--r--src/StardewModdingAPI/Program.cs29
4 files changed, 30 insertions, 7 deletions
diff --git a/README.md b/README.md
index c90e62cc..74388144 100644
--- a/README.md
+++ b/README.md
@@ -145,9 +145,10 @@ field | purpose
`ModCompatibility` | A list of mod versions SMAPI should consider compatible or broken regardless of whether it detects incompatible code. Each record can be set to `AssumeCompatible` or `AssumeBroken`. Changing this field is not recommended and may destabilise your game.
### Command-line arguments
-SMAPI recognises the following command-line arguments. These are intended for internal use and may
-change without warning.
+SMAPI recognises the following command-line arguments. These are intended for internal use or
+testing and may change without warning.
argument | purpose
-------- | -------
+`--log path "path"` | The relative or absolute path of the log file SMAPI should write.
`--no-terminal` | SMAPI won't write anything to the console window. (Messages will still be written to the log file.)
diff --git a/release-notes.md b/release-notes.md
index bde3e4b0..a5ef4a0b 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -43,6 +43,7 @@ For mod developers:
* Added `ContentEvents.AfterLocaleChanged` event triggered when the player changes the content language (for the upcoming Stardew Valley 1.2).
* Added `SaveEvents.AfterReturnToTitle` event triggered when the player returns to the title screen (for the upcoming Stardew Valley 1.2).
* Added `helper.Reflection.GetPrivateProperty` method.
+* Added a `--log-path` argument to specify the SMAPI log path during testing.
* SMAPI now writes XNA input enums (`Buttons` and `Keys`) to JSON as strings automatically, so mods no longer need to add a `StringEnumConverter` themselves for those.
* The SMAPI log now has a simpler filename.
* The SMAPI log now shows the OS caption (like "Windows 10") instead of its internal version when available.
diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs
index e28b33d7..4a036cd0 100644
--- a/src/StardewModdingAPI/Constants.cs
+++ b/src/StardewModdingAPI/Constants.cs
@@ -69,7 +69,7 @@ namespace StardewModdingAPI
internal static string ApiConfigPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.config.json");
/// <summary>The file path to the log where the latest output should be saved.</summary>
- internal static string LogPath => Path.Combine(Constants.LogDir, "SMAPI-latest.txt");
+ internal static string DefaultLogPath => Path.Combine(Constants.LogDir, "SMAPI-latest.txt");
/// <summary>The full path to the folder containing mods.</summary>
internal static string ModPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods");
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index ac98f2e4..58850dc3 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -30,7 +30,7 @@ namespace StardewModdingAPI
** Properties
*********/
/// <summary>The log file to which to write messages.</summary>
- private readonly LogFileManager LogFile = new LogFileManager(Constants.LogPath);
+ private readonly LogFileManager LogFile;
/// <summary>Manages console output interception.</summary>
private readonly ConsoleInterceptionManager ConsoleManager = new ConsoleInterceptionManager();
@@ -67,17 +67,38 @@ namespace StardewModdingAPI
/// <param name="args">The command-line arguments.</param>
private static void Main(string[] args)
{
- new Program(writeToConsole: !args.Contains("--no-terminal"))
+ // get flags from arguments
+ bool writeToConsole = !args.Contains("--no-terminal");
+
+ // get log path from arguments
+ string logPath = null;
+ {
+ int pathIndex = Array.LastIndexOf(args, "--log-path") + 1;
+ if (pathIndex >= 1 && args.Length >= pathIndex)
+ {
+ logPath = args[pathIndex];
+ if (!Path.IsPathRooted(logPath))
+ logPath = Path.Combine(Constants.LogDir, logPath);
+ }
+ }
+ if (string.IsNullOrWhiteSpace(logPath))
+ logPath = Constants.DefaultLogPath;
+
+ // load SMAPI
+ new Program(writeToConsole, logPath)
.LaunchInteractively();
}
/// <summary>Construct an instance.</summary>
- internal Program(bool writeToConsole)
+ /// <param name="writeToConsole">Whether to output log messages to the console.</param>
+ /// <param name="logPath">The full file path to which to write log messages.</param>
+ internal Program(bool writeToConsole, string logPath)
{
// load settings
this.Settings = JsonConvert.DeserializeObject<SConfig>(File.ReadAllText(Constants.ApiConfigPath));
// initialise
+ this.LogFile = new LogFileManager(logPath);
this.Monitor = new Monitor("SMAPI", this.ConsoleManager, this.LogFile, this.ExitGameImmediately) { WriteToConsole = writeToConsole };
this.ModRegistry = new ModRegistry(this.Settings.ModCompatibility);
this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry);
@@ -460,7 +481,7 @@ namespace StardewModdingAPI
try
{
int modEntries = modAssembly.DefinedTypes.Count(type => typeof(Mod).IsAssignableFrom(type) && !type.IsAbstract);
- if(modEntries == 0)
+ if (modEntries == 0)
{
this.Monitor.Log($"{skippedPrefix} because its DLL has no '{nameof(Mod)}' subclass.", LogLevel.Error);
continue;