diff --git a/ID3SQL/ID3SQL/CommandLineOptions.cs b/ID3SQL/ID3SQL/CommandLineOptions.cs index e07c0a1..6b46c5d 100644 --- a/ID3SQL/ID3SQL/CommandLineOptions.cs +++ b/ID3SQL/ID3SQL/CommandLineOptions.cs @@ -1,4 +1,6 @@ using System; +using System.Text; +using System.Collections.Generic; using CommandLine; using CommandLine.Text; @@ -43,7 +45,33 @@ public class CommandLineOptions [HelpOption] public string GetUsage() { - return HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current)); + StringBuilder sb = new StringBuilder(); + sb.AppendLine(HelpText.AutoBuild(this, (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current))); + + sb.AppendLine(); + sb.AppendLine("Available Getters"); + sb.AppendLine(); + + IEnumerable getterPropertyNames = TagFunctionManager.AllGetFunctionPropertyNames(); + foreach(string getterPropertyName in getterPropertyNames) + { + sb.AppendLine(getterPropertyName); + } + + sb.AppendLine(); + sb.AppendLine("Available Setters"); + sb.AppendLine(); + + IEnumerable setterPropertyNames = TagFunctionManager.AllSetFunctionPropertyNames(); + foreach(string setterPropertyName in setterPropertyNames) + { + sb.AppendLine(setterPropertyName); + } + + sb.AppendLine(); + sb.AppendLine("Getter and Setter Property names are case-sensitive"); + + return sb.ToString(); } } } diff --git a/ID3SQL/ID3SQL/ExecutionPlan.cs b/ID3SQL/ID3SQL/ExecutionPlan.cs index b6bfca1..16bf1c6 100644 --- a/ID3SQL/ID3SQL/ExecutionPlan.cs +++ b/ID3SQL/ID3SQL/ExecutionPlan.cs @@ -56,9 +56,10 @@ private static void PrintParseTree(ParseTreeNode parseTreeNode, int level) { for(int i = 0; i < level; i++) { - Console.Write('\t'); + Console.Error.Write('\t'); } - Console.WriteLine(parseTreeNode); + + Console.Error.WriteLine(parseTreeNode); foreach(ParseTreeNode childNode in parseTreeNode.ChildNodes) { @@ -232,6 +233,10 @@ private static Func ToExpressionFunc { string propertyName = node.Token.Text; Func getFn = TagFunctionManager.GetFunction(propertyName); + if(getFn == null) + { + throw new ID3SQLException(string.Format("Unknown property name in expression: {0}", propertyName)); + } expressionFn = (file, filePath, executionPlanOptions) => { return getFn(file, filePath); @@ -694,7 +699,7 @@ private static Action ToSelectAction(ParseTr } else { - throw new ID3SQLException("Unknown property name in select list"); + throw new ID3SQLException(string.Format("Unknown property name in select list: {0}", propertyName)); } } action = (file, filePath, executionPlanOptions) => @@ -789,11 +794,11 @@ private static Action ToUpdateAction(ParseTr } catch(Exception ex) { - Console.WriteLine(string.Format("Failed to write {0}", filePath)); + Console.Error.WriteLine(string.Format("Failed to write {0}", filePath)); if(executionPlanOptions.Verbose) { - Console.WriteLine(ex); + Console.Error.WriteLine(ex); } } diff --git a/ID3SQL/ID3SQL/Program.cs b/ID3SQL/ID3SQL/Program.cs index 58eb8e8..975ce12 100644 --- a/ID3SQL/ID3SQL/Program.cs +++ b/ID3SQL/ID3SQL/Program.cs @@ -61,7 +61,7 @@ public static void Main(string[] args) } catch(Exception ex) { - throw new ID3SQLException(string.Format("Error building file list from startDirectory '{0}'", startDirectory), ex); + throw new ID3SQLException(string.Format("Error building file list from start directory '{0}'", startDirectory), ex); } ExecutionPlanOptions executionPlanOptions = new ExecutionPlanOptions() @@ -75,23 +75,23 @@ public static void Main(string[] args) ColumnSeparator = options.ColumnSeparator }; - executionPlan.Invoke(tagFilePaths, executionPlanOptions); + executionPlan(tagFilePaths, executionPlanOptions); } } catch(ID3SQLException ex) { - Console.WriteLine(ex.Message); + Console.Error.WriteLine(ex.Message); if(options.Verbose) { - Console.Write(ex); + Console.Error.Write(ex); } } catch(Exception ex) { - Console.WriteLine("Unknown error has occured"); + Console.Error.WriteLine("Unknown error has occured"); if(options.Verbose) { - Console.WriteLine(ex); + Console.Error.WriteLine(ex); } } } diff --git a/ID3SQL/ID3SQL/TagFunctionManager.cs b/ID3SQL/ID3SQL/TagFunctionManager.cs index b3d976d..013ed62 100644 --- a/ID3SQL/ID3SQL/TagFunctionManager.cs +++ b/ID3SQL/ID3SQL/TagFunctionManager.cs @@ -283,6 +283,21 @@ public static Action SetFunction(string prop } } + public static IEnumerable AllSetFunctionPropertyNames(Comparison comparison = null) + { + if (comparison != null) + { + List keys = _SetFunctions.Keys.ToList(); + keys.Sort(comparison); + + return keys; + } + else + { + return _SetFunctions.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Key); + } + } + private static readonly IDictionary> _SetFunctions = new Dictionary>() { {