Return specific error codes from command execution.

This commit is contained in:
2019-01-05 19:50:56 +00:00
parent 104bc55c5e
commit 372f9f68ac
28 changed files with 351 additions and 204 deletions

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -45,9 +46,9 @@ namespace DiscImageChef.Commands
{
string encodingName;
string inputFile;
bool searchForFilesystems = true;
bool searchForPartitions = true;
bool showHelp;
bool searchForFilesystems = true;
bool searchForPartitions = true;
bool showHelp;
public AnalyzeCommand() : base("analyze",
"Analyzes a disc image and searches for partitions and/or filesystems.")
@@ -74,7 +75,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -84,13 +85,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -108,7 +109,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 2;
return (int)ErrorNumber.CannotOpenFile;
}
Encoding encoding = null;
@@ -122,7 +123,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return 5;
return (int)ErrorNumber.EncodingUnknown;
}
PluginBase plugins = GetPluginBase.Instance;
@@ -136,7 +137,7 @@ namespace DiscImageChef.Commands
if(imageFormat == null)
{
DicConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return 3;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -151,7 +152,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 4;
return (int)ErrorNumber.CannotOpenFormat;
}
if(MainClass.Verbose)
@@ -169,7 +170,7 @@ namespace DiscImageChef.Commands
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
DicConsole.DebugWriteLine("Analyze command", "Stack trace: {0}", ex.StackTrace);
return -1;
return (int)ErrorNumber.CannotOpenFormat;
}
List<string> idPlugins;
@@ -186,7 +187,7 @@ namespace DiscImageChef.Commands
if(!searchForFilesystems)
{
DicConsole.WriteLine("No partitions founds, not searching for filesystems");
return -2;
return (int)ErrorNumber.NothingFound;
}
checkraw = true;
@@ -283,10 +284,11 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
DicConsole.DebugWriteLine("Analyze command", ex.StackTrace);
return (int)ErrorNumber.UnexpectedException;
}
Statistics.AddCommand("analyze");
return 0;
return (int)ErrorNumber.NoError;
}
}
}