@@ -19,7 +19,7 @@ public static class MainClass
1919 private static readonly ILog Log =
2020 LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2121
22- public const string Version = "1.3.4 " ;
22+ public const string Version = "1.4.0 " ;
2323
2424 public static void Main ( string [ ] args )
2525 {
@@ -390,11 +390,11 @@ private static void RegularParametersParsing(string[] args)
390390 } ,
391391 {
392392 "f=|format=" ,
393- "The spectra output format: 0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet. Defaults to indexed mzML if no format is specified." ,
393+ "The spectra output format: 0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet; both numeric and text (case insensitive) value recognized . Defaults to indexed mzML if no format is specified." ,
394394 v => outputFormatString = v
395395 } ,
396396 {
397- "m=|metadata=" , "The metadata output format: 0 for JSON, 1 for TXT. " ,
397+ "m=|metadata=" , "The metadata output format: 0 for JSON, 1 for TXT; both numeric and text (case insensitive) value recognized " ,
398398 v => metadataFormatString = v
399399 } ,
400400 {
@@ -422,15 +422,15 @@ private static void RegularParametersParsing(string[] args)
422422 v => parseInput . AllDetectors = v != null
423423 } ,
424424 {
425- "l=|logging=" , "Optional logging level: 0 for silent, 1 for verbose." ,
425+ "l=|logging=" , "Optional logging level: 0 for silent, 1 for verbose; both numeric and text (case insensitive) value recognized ." ,
426426 v => logFormatString = v
427427 } ,
428428 {
429429 "e|ignoreInstrumentErrors" , "Ignore missing properties by the instrument." ,
430430 v => parseInput . IgnoreInstrumentErrors = v != null
431431 } ,
432432 {
433- "x|includeExceptionData " , "Include reference and exception data" ,
433+ "x|excludeExceptionData " , "Exclude reference and exception data" ,
434434 v => parseInput . ExData = v != null
435435 } ,
436436 {
@@ -585,54 +585,12 @@ private static void RegularParametersParsing(string[] args)
585585
586586 if ( outputFormatString != null )
587587 {
588- int outPutFormatInt ;
589- try
590- {
591- outPutFormatInt = int . Parse ( outputFormatString ) ;
592- }
593- catch ( FormatException )
594- {
595- throw new OptionException (
596- "unknown output format value (0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet)" ,
597- "-f, --format" ) ;
598- }
599-
600- if ( Enum . IsDefined ( typeof ( OutputFormat ) , outPutFormatInt ) &&
601- ( ( OutputFormat ) outPutFormatInt ) != OutputFormat . NONE )
602- {
603- parseInput . OutputFormat = ( OutputFormat ) outPutFormatInt ;
604- }
605- else
606- {
607- throw new OptionException (
608- "unknown output format value (0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet)" ,
609- "-f, --format" ) ;
610- }
588+ parseInput . OutputFormat = ( OutputFormat ) ParseToEnum ( typeof ( OutputFormat ) , outputFormatString , "-f, --format" ) ;
611589 }
612590
613591 if ( metadataFormatString != null )
614592 {
615- int metadataInt ;
616- try
617- {
618- metadataInt = int . Parse ( metadataFormatString ) ;
619- }
620- catch ( FormatException )
621- {
622- throw new OptionException ( "unknown metadata format value (0 for JSON, 1 for TXT)" ,
623- "-m, --metadata" ) ;
624- }
625-
626- if ( Enum . IsDefined ( typeof ( MetadataFormat ) , metadataInt ) &&
627- ( ( MetadataFormat ) metadataInt ) != MetadataFormat . NONE )
628- {
629- parseInput . MetadataFormat = ( MetadataFormat ) metadataInt ;
630- }
631- else
632- {
633- throw new OptionException ( "unknown metadata format value (0 for JSON, 1 for TXT)" ,
634- "-m, --metadata" ) ;
635- }
593+ parseInput . MetadataFormat = ( MetadataFormat ) ParseToEnum ( typeof ( MetadataFormat ) , metadataFormatString , "-m, --metadata" ) ;
636594 }
637595
638596 if ( parseInput . MetadataOutputFile != null && Directory . Exists ( parseInput . MetadataOutputFile ) )
@@ -657,29 +615,7 @@ private static void RegularParametersParsing(string[] args)
657615
658616 if ( logFormatString != null )
659617 {
660- int logFormatInt ;
661- try
662- {
663- logFormatInt = int . Parse ( logFormatString ) ;
664- }
665- catch ( FormatException )
666- {
667- throw new OptionException ( "unknown log format value (0 for silent, 1 for verbose)" ,
668- "-l, --logging" ) ;
669- }
670-
671- if ( Enum . IsDefined ( typeof ( LogFormat ) , logFormatInt ) )
672- {
673- if ( ( LogFormat ) logFormatInt != LogFormat . NONE )
674- {
675- parseInput . LogFormat = ( LogFormat ) logFormatInt ;
676- }
677- }
678- else
679- {
680- throw new OptionException ( "unknown log format value (0 for silent, 1 for verbose)" ,
681- "-l, --logging" ) ;
682- }
618+ parseInput . LogFormat = ( LogFormat ) ParseToEnum ( typeof ( LogFormat ) , logFormatString , "-l, --logging" ) ;
683619 }
684620
685621 if ( parseInput . StdOut )
@@ -796,6 +732,49 @@ private static void ShowHelp(string message, OptionException optionException, Op
796732 Environment . Exit ( - 1 ) ;
797733 }
798734
735+ private static string GetValidEnumLevels ( Type enumType )
736+ {
737+ List < string > output = new List < string > ( ) ;
738+ foreach ( int v in Enum . GetValues ( enumType ) )
739+ {
740+ output . Add ( String . Format ( "{0} ({1})" , Enum . GetName ( enumType , v ) , v ) ) ;
741+ }
742+
743+ return String . Join ( "\n " , output ) ;
744+ }
745+
746+ private static int ParseToEnum ( Type enumType , string formatString , string keyName )
747+ {
748+ if ( int . TryParse ( formatString , out var formatInt ) ) //can be parsed as int
749+ {
750+ if ( Enum . IsDefined ( enumType , formatInt ) )
751+ {
752+ return formatInt ;
753+ }
754+ else
755+ {
756+ throw new OptionException (
757+ String . Format ( "unknown format value, the following values recognized (case insensitive)\n {0}" , GetValidEnumLevels ( enumType ) ) ,
758+ keyName ) ;
759+ }
760+
761+ }
762+ else //try parse as a string
763+ {
764+ try
765+ {
766+ return ( int ) Enum . Parse ( enumType , formatString , true ) ;
767+ }
768+
769+ catch ( Exception )
770+ {
771+ throw new OptionException (
772+ String . Format ( "unknown format value, the following values recognized (case insensitive)\n {0}" , GetValidEnumLevels ( enumType ) ) ,
773+ keyName ) ;
774+ }
775+ }
776+ }
777+
799778 private static HashSet < int > ParseMsLevel ( string inputString )
800779 {
801780 HashSet < int > result = new HashSet < int > ( ) ;
0 commit comments