11#region License
2- //
3- // Your Project Name Here: Program.cs
4- //
5- // Author:
6- // Your Name Here ([email protected] ) 7- //
8- // Copyright (C) 2012 Your Name Here
2+ // <copyright file="Program.cs" company="Your name here">
3+ // Copyright 2013 Your name here
4+ // </copyright>
95//
106// [License Body Here]
117#endregion
12- #region Using Directives
13- using System ;
14- using CommandLine ;
15- using CommandLine . Text ;
16- #endregion
178
189namespace CSharpTemplate
1910{
20- sealed class Program
21- {
22- sealed class Options : CommandLineOptionsBase
23- {
24- [ Option ( "t" , "text" , Required = true , HelpText = "text value here" ) ]
25- public string TextValue { get ; set ; }
26-
27- [ Option ( "n" , "numeric" , HelpText = "numeric value here" ) ]
28- public double NumericValue { get ; set ; }
29-
30- [ Option ( "b" , "bool" , HelpText = "on|off switch here" ) ]
31- public bool BooleanValue { get ; set ; }
32-
33- [ HelpOption ]
34- public string GetUsage ( )
35- {
36- var help = new HelpText {
37- Heading = new HeadingInfo ( ThisAssembly . Title , ThisAssembly . InformationalVersion ) ,
38- Copyright = new CopyrightInfo ( ThisAssembly . Author , 2012 ) ,
39- AdditionalNewLineAfterOption = true ,
40- AddDashesToOption = true
41- } ;
42- this . HandleParsingErrorsInHelp ( help ) ;
43- help . AddPreOptionsLine ( "<<license details here.>>" ) ;
44- help . AddPreOptionsLine ( "Usage: CSharpTemplate -tSomeText --numeric 2012 -b" ) ;
45- help . AddOptions ( this ) ;
46-
47- return help ;
48- }
49-
50- void HandleParsingErrorsInHelp ( HelpText help )
51- {
52- if ( this . LastPostParsingState . Errors . Count > 0 )
53- {
54- var errors = help . RenderParsingErrorsText ( this , 2 ) ; // indent with two spaces
55- if ( ! string . IsNullOrEmpty ( errors ) )
56- {
57- help . AddPreOptionsLine ( string . Concat ( Environment . NewLine , "ERROR(S):" ) ) ;
58- help . AddPreOptionsLine ( errors ) ;
59- }
60- }
61- }
62- }
63-
64- static void Main ( string [ ] args )
65- {
66- var options = new Options ( ) ;
67- if ( CommandLineParser . Default . ParseArguments ( args , options ) )
68- {
69- Console . WriteLine ( "t|ext: " + options . TextValue ) ;
70- Console . WriteLine ( "n|umeric: " + options . NumericValue . ToString ( ) ) ;
71- Console . WriteLine ( "b|ool: " + options . BooleanValue . ToString ( ) . ToLower ( ) ) ;
72- }
73- }
74- }
75- }
11+ #region Using Directives
12+ using System ;
13+ using CommandLine ;
14+ using CommandLine . Text ;
15+ #endregion
16+
17+ internal class Program
18+ {
19+ static void Main ( string [ ] args )
20+ {
21+ var options = new Options ( ) ;
22+
23+ if ( ! CommandLine . Parser . Default . ParseArguments ( args , options ) )
24+ {
25+ Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
26+ }
27+
28+ Console . WriteLine ( "t|ext: " + options . TextValue ) ;
29+ Console . WriteLine ( "n|umeric: " + options . NumericValue ) ;
30+ Console . WriteLine ( "b|ool: " + options . BooleanValue . ToString ( ) . ToLowerInvariant ( ) ) ;
31+ }
32+ }
33+ }
0 commit comments