1 // HtmlAgilityPack V1.0 - Simon Mourier <simon underscore mourier at hotmail dot com>
4 namespace HtmlAgilityPack
6 internal class HtmlCmdLine
10 internal static bool Help
;
24 #region Internal Methods
26 internal static string GetOption(string name
, string def
)
29 string[] args
= Environment
.GetCommandLineArgs();
30 for (int i
= 1; i
< args
.Length
; i
++)
32 GetStringArg(args
[i
], name
, ref p
);
37 internal static string GetOption(int index
, string def
)
40 string[] args
= Environment
.GetCommandLineArgs();
42 for (int i
= 1; i
< args
.Length
; i
++)
44 if (GetStringArg(args
[i
], ref p
))
56 internal static bool GetOption(string name
, bool def
)
59 string[] args
= Environment
.GetCommandLineArgs();
60 for (int i
= 1; i
< args
.Length
; i
++)
62 GetBoolArg(args
[i
], name
, ref p
);
67 internal static int GetOption(string name
, int def
)
70 string[] args
= Environment
.GetCommandLineArgs();
71 for (int i
= 1; i
< args
.Length
; i
++)
73 GetIntArg(args
[i
], name
, ref p
);
80 #region Private Methods
82 private static void GetBoolArg(string Arg
, string Name
, ref bool ArgValue
)
84 if (Arg
.Length
< (Name
.Length
+ 1)) // -name is 1 more than name
86 if (('/' != Arg
[0]) && ('-' != Arg
[0])) // not a param
88 if (Arg
.Substring(1, Name
.Length
).ToLower() == Name
.ToLower())
92 private static void GetIntArg(string Arg
, string Name
, ref int ArgValue
)
94 if (Arg
.Length
< (Name
.Length
+ 3)) // -name:12 is 3 more than name
96 if (('/' != Arg
[0]) && ('-' != Arg
[0])) // not a param
98 if (Arg
.Substring(1, Name
.Length
).ToLower() == Name
.ToLower())
102 ArgValue
= Convert
.ToInt32(Arg
.Substring(Name
.Length
+ 2, Arg
.Length
- Name
.Length
- 2));
110 private static bool GetStringArg(string Arg
, ref string ArgValue
)
112 if (('/' == Arg
[0]) || ('-' == Arg
[0]))
118 private static void GetStringArg(string Arg
, string Name
, ref string ArgValue
)
120 if (Arg
.Length
< (Name
.Length
+ 3)) // -name:x is 3 more than name
122 if (('/' != Arg
[0]) && ('-' != Arg
[0])) // not a param
124 if (Arg
.Substring(1, Name
.Length
).ToLower() == Name
.ToLower())
125 ArgValue
= Arg
.Substring(Name
.Length
+ 2, Arg
.Length
- Name
.Length
- 2);
128 private static void ParseArgs()
130 string[] args
= Environment
.GetCommandLineArgs();
131 for (int i
= 1; i
< args
.Length
; i
++)
134 GetBoolArg(args
[i
], "?", ref Help
);
135 GetBoolArg(args
[i
], "h", ref Help
);
136 GetBoolArg(args
[i
], "help", ref Help
);