\hypertarget{class_qore_1_1_get_opt}{}\section{Qore\+::Get\+Opt Class Reference}
\label{class_qore_1_1_get_opt}\index{Qore::GetOpt@{Qore::GetOpt}}


The Get\+Opt class provides an easy way to process P\+O\+S\+I\+X-\/style command-\/line options in Qore scripts/programs.  


\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{class_qore_1_1_get_opt_a2cf1645b06c2dae81141c40b3dd6dfe2}{constructor}} (\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ options)
\begin{DoxyCompactList}\small\item\em Creates the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} object and sets the option hash with the single required argument. \end{DoxyCompactList}\item 
\mbox{\hyperlink{class_qore_1_1_get_opt_a6995cd4908723b8d166235ac65ba8bb3}{copy}} ()
\begin{DoxyCompactList}\small\item\em Throws an exception; objects of this class cannot be copied. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{parse}} (reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the parameter list according to the option hash passed to the constructor. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a1e0267d9c8fe2785cfce2b115d77802e}{parse}} (softlist$<$ auto $>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the parameter list according to the option hash passed to the constructor. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}{parse2}} (reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the parameter list according to the option hash passed to the constructor. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a2977199c93490409e08ad702f0691817}{parse2}} (softlist$<$ auto $>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the parameter list according to the option hash passed to the constructor. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a3c16b85019b063a45251c27314379a06}{parse3}} (reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the parameter list according to the option hash passed to the constructor and displays an explanatory error message on stderr and exits the program if an error occurs. \end{DoxyCompactList}\item 
\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a1e35348c2a154a13ec09cd591b80b23d}{parse3}} (softlist$<$ auto $>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the parameter list according to the option hash passed to the constructor and displays an explanatory error message on stderr and exits the program if an error occurs. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Static Public Member Functions}
\begin{DoxyCompactItemize}
\item 
static \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a5d44ae257207066002e11d76600bfc61}{parse}} (\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ opts, reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the given options and returns a hash of the parsed options. \end{DoxyCompactList}\item 
static \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_a0623e1c6ad888a7b1ecba22cf9da1db9}{parse\+Ex}} (\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ opts, reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the given options and returns a hash of the parsed options and throws and exception if there are any errors. \end{DoxyCompactList}\item 
static \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ \mbox{\hyperlink{class_qore_1_1_get_opt_ac7c14bec422068688736aac2557e427b}{parse\+Exit}} (\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$ opts, reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$ pgm\+\_\+args)
\begin{DoxyCompactList}\small\item\em Parses the given options and returns a hash of the parsed options; prints out an error message and exits the program if there are any errors. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
The Get\+Opt class provides an easy way to process P\+O\+S\+I\+X-\/style command-\/line options in Qore scripts/programs. 

\subsection{Member Function Documentation}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a2cf1645b06c2dae81141c40b3dd6dfe2}\label{class_qore_1_1_get_opt_a2cf1645b06c2dae81141c40b3dd6dfe2}} 
\index{Qore::GetOpt@{Qore::GetOpt}!constructor@{constructor}}
\index{constructor@{constructor}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{constructor()}{constructor()}}
{\footnotesize\ttfamily Qore\+::\+Get\+Opt\+::constructor (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$}]{options }\end{DoxyParamCaption})}



Creates the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} object and sets the option hash with the single required argument. 


\begin{DoxyParams}{Parameters}
{\em options} & Each key defines the key value for the return hash if any arguments are given corresponding to the string value of the key; The string value of each hash key follows the following pattern\+:~\newline
 {\itshape opts}{\ttfamily \mbox{[}(=$\vert$\+:)}{\itshape type}{\ttfamily \mbox{[}}{\itshape modifier}{\ttfamily \mbox{]}\mbox{]}}~\newline
 Where the meaning of the above placeholders in italics is\+:~\newline

\begin{DoxyItemize}
\item {\itshape opts}\+: At least one short option and/or a long option name; if both are present, then they must be separated by a comma. The short option must be a single character.
\item {\ttfamily (=$\vert$\+:)}{\itshape type}\+: if {\ttfamily \char`\"{}=\char`\"{}} is used, then the option takes a mandatory argument, if {\ttfamily \char`\"{}\+:\char`\"{}} is used, then the argument is optional. Types are specified as follows\+:
\begin{DoxyItemize}
\item {\itshape s}\+: string
\item {\itshape i}\+: integer
\item {\itshape f}\+: float
\item {\itshape d}\+: date
\item {\itshape b}\+: boolean
\end{DoxyItemize}
\item {\itshape modifier}\+: {\ttfamily \char`\"{}@\char`\"{}} specifies a list, {\ttfamily \char`\"{}+\char`\"{}} an additive value (sum; must be integer or float type)
\end{DoxyItemize}\\
\hline
\end{DoxyParams}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{const ProgramPptions = (}
\DoxyCodeLine{     \textcolor{stringliteral}{"url"}  : \textcolor{stringliteral}{"u,url=s"},}
\DoxyCodeLine{     \textcolor{stringliteral}{"xml"}  : \textcolor{stringliteral}{"x,xml"},}
\DoxyCodeLine{     \textcolor{stringliteral}{"lxml"} : \textcolor{stringliteral}{"X,literal-xml"},}
\DoxyCodeLine{     \textcolor{stringliteral}{"verb"} : \textcolor{stringliteral}{"v,verbose"},}
\DoxyCodeLine{     \textcolor{stringliteral}{"help"} : \textcolor{stringliteral}{"h,help"},}
\DoxyCodeLine{ );}
\DoxyCodeLine{}
\DoxyCodeLine{GetOpt getopt(ProgramOptions);}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em G\+E\+T\+O\+P\+T-\/\+P\+A\+R\+A\+M\+E\+T\+E\+R-\/\+E\+R\+R\+OR} & option key value is not a string; {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} used as option key \\
\hline
{\em G\+E\+T\+O\+P\+T-\/\+O\+P\+T\+I\+O\+N-\/\+E\+R\+R\+OR} & list option specified as optional; empty option key value string; multiple long options given for key; duplicate options given; invalid attributes for option; unknown modifier given for option \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a6995cd4908723b8d166235ac65ba8bb3}\label{class_qore_1_1_get_opt_a6995cd4908723b8d166235ac65ba8bb3}} 
\index{Qore::GetOpt@{Qore::GetOpt}!copy@{copy}}
\index{copy@{copy}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{copy()}{copy()}}
{\footnotesize\ttfamily Qore\+::\+Get\+Opt\+::copy (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Throws an exception; objects of this class cannot be copied. 


\begin{DoxyExceptions}{Exceptions}
{\em G\+E\+T\+O\+P\+T-\/\+C\+O\+P\+Y-\/\+E\+R\+R\+OR} & copying \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} objects is not supported \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}\label{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse@{parse}}
\index{parse@{parse}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse()}{parse()}\hspace{0.1cm}{\footnotesize\ttfamily [1/3]}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse (\begin{DoxyParamCaption}\item[{reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$}]{pgm\+\_\+args }\end{DoxyParamCaption})}



Parses the parameter list according to the option hash passed to the constructor. 

All arguments parsed will be removed from the list reference passed as the sole argument, leaving only unparsed arguments (for example, file names).

If any errors are encountered, the return value hash will have a key {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} giving a list of error messages pertaining to the options parsed.


\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & The reference should point to a list of arguments to process (normally {\ttfamily A\+R\+GV}); any argument accepted by the object will be removed from the list\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument. The hash key {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} will contain any errors.
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse(\(\backslash\)ARGV);}
\DoxyCodeLine{\textcolor{keywordflow}{if} (exists o.\textcolor{stringliteral}{"\_ERRORS\_"}) \{}
\DoxyCodeLine{    foreach string err \textcolor{keywordflow}{in} (o.\textcolor{stringliteral}{"\_ERRORS\_"})}
\DoxyCodeLine{        stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, err);}
\DoxyCodeLine{    \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}{Get\+Opt\+::parse2()}} for a similar method that throws an exception instead of putting error information in the {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} key of the \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}} value returned 
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a1e0267d9c8fe2785cfce2b115d77802e}\label{class_qore_1_1_get_opt_a1e0267d9c8fe2785cfce2b115d77802e}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse@{parse}}
\index{parse@{parse}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse()}{parse()}\hspace{0.1cm}{\footnotesize\ttfamily [2/3]}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse (\begin{DoxyParamCaption}\item[{softlist$<$ auto $>$}]{pgm\+\_\+args }\end{DoxyParamCaption})}



Parses the parameter list according to the option hash passed to the constructor. 

If any errors are encountered, the return value hash will have a key {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} giving a list of error messages pertaining to the options parsed.


\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & A list of arguments to process\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument. The hash key {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} will contain any errors.
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse(ARGV);}
\DoxyCodeLine{\textcolor{keywordflow}{if} (o.\_ERRORS\_) \{}
\DoxyCodeLine{    map stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, \$1), o.\_ERRORS\_;}
\DoxyCodeLine{    \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}{Get\+Opt\+::parse2()}} for a similar method that throws an exception instead of putting error information in the {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} key of the \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}} value returned 
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a5d44ae257207066002e11d76600bfc61}\label{class_qore_1_1_get_opt_a5d44ae257207066002e11d76600bfc61}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse@{parse}}
\index{parse@{parse}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse()}{parse()}\hspace{0.1cm}{\footnotesize\ttfamily [3/3]}}
{\footnotesize\ttfamily static \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$}]{opts,  }\item[{reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$}]{pgm\+\_\+args }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



Parses the given options and returns a hash of the parsed options. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse(\(\backslash\)ARGV);}
\DoxyCodeLine{\textcolor{keywordflow}{if} (exists o.\textcolor{stringliteral}{"\_ERRORS\_"}) \{}
\DoxyCodeLine{    foreach string err \textcolor{keywordflow}{in} (o.\textcolor{stringliteral}{"\_ERRORS\_"})}
\DoxyCodeLine{        stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, err);}
\DoxyCodeLine{    \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & The reference should point to a list of arguments to process (normally {\ttfamily A\+R\+GV}); any argument accepted by the object will be removed from the list\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument. The hash key {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} will contain any errors.
\end{DoxyReturn}
All arguments parsed will be removed from {\itshape pgm\+\_\+args}, leaving only unparsed arguments (for example, file names).

If any errors are encountered, the return value hash will have a key {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} giving a list of error messages pertaining to the options parsed.

\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a0623e1c6ad888a7b1ecba22cf9da1db9}{Get\+Opt\+::parse\+Ex(hash$<$auto$>$, reference$<$list$<$string$>$$>$)}}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_ac7c14bec422068688736aac2557e427b}{Get\+Opt\+::parse\+Exit(hash$<$auto$>$, reference$<$list$<$string$>$$>$)}} 
\end{DoxyItemize}
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}\label{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse2@{parse2}}
\index{parse2@{parse2}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse2()}{parse2()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse2 (\begin{DoxyParamCaption}\item[{reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$}]{pgm\+\_\+args }\end{DoxyParamCaption})}



Parses the parameter list according to the option hash passed to the constructor. 

If any errors are encountered, an appropriate exception will be thrown.


\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & The reference should point to a list of arguments to process (normally {\ttfamily A\+R\+GV}); any argument accepted by the object will be removed from the list\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{try} \{}
\DoxyCodeLine{   hash<auto> o = getopt.parse2(\(\backslash\)ARGV);}
\DoxyCodeLine{\} catch (hash<ExceptionInfo> ex) \{}
\DoxyCodeLine{   stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, ex.desc);}
\DoxyCodeLine{   \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em G\+E\+T\+O\+P\+T-\/\+E\+R\+R\+OR} & error parsing arguments\\
\hline
\end{DoxyExceptions}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{Get\+Opt\+::parse()}} for a similar method that puts error information in the {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} key of the \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}} value returned instead of throwing an exception 
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a2977199c93490409e08ad702f0691817}\label{class_qore_1_1_get_opt_a2977199c93490409e08ad702f0691817}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse2@{parse2}}
\index{parse2@{parse2}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse2()}{parse2()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse2 (\begin{DoxyParamCaption}\item[{softlist$<$ auto $>$}]{pgm\+\_\+args }\end{DoxyParamCaption})}



Parses the parameter list according to the option hash passed to the constructor. 

If any errors are encountered, an appropriate exception will be thrown.


\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & A list of arguments to process\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{try} \{}
\DoxyCodeLine{   hash<auto> o = getopt.parse2(ARGV);}
\DoxyCodeLine{\} catch (hash<ExceptionInfo> ex) \{}
\DoxyCodeLine{   stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, ex.desc);}
\DoxyCodeLine{   \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em G\+E\+T\+O\+P\+T-\/\+E\+R\+R\+OR} & error parsing arguments\\
\hline
\end{DoxyExceptions}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{Get\+Opt\+::parse()}} for a similar method that puts error information in the {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} key of the \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}} value returned instead of throwing an exception 
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a3c16b85019b063a45251c27314379a06}\label{class_qore_1_1_get_opt_a3c16b85019b063a45251c27314379a06}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse3@{parse3}}
\index{parse3@{parse3}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse3()}{parse3()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse3 (\begin{DoxyParamCaption}\item[{reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$}]{pgm\+\_\+args }\end{DoxyParamCaption})}



Parses the parameter list according to the option hash passed to the constructor and displays an explanatory error message on stderr and exits the program if an error occurs. 

\begin{DoxyParagraph}{Restrictions\+:}
\mbox{\hyperlink{group__parse__options_ga10d8e3f76c427b0f974529de572dd0ec}{Qore\+::\+P\+O\+\_\+\+N\+O\+\_\+\+P\+R\+O\+C\+E\+S\+S\+\_\+\+C\+O\+N\+T\+R\+OL}}
\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & The reference should point to a list of arguments to process (normally {\ttfamily A\+R\+GV}); any argument accepted by the object will be removed from the list\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse3(\(\backslash\)ARGV);}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{Get\+Opt\+::parse()}} for a similar method that puts error information in the {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} key of the \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}} value returned
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}{Get\+Opt\+::parse2()}} for a similar method that throws exceptions instead of exiting the program 
\end{DoxyItemize}
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a1e35348c2a154a13ec09cd591b80b23d}\label{class_qore_1_1_get_opt_a1e35348c2a154a13ec09cd591b80b23d}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parse3@{parse3}}
\index{parse3@{parse3}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parse3()}{parse3()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse3 (\begin{DoxyParamCaption}\item[{softlist$<$ auto $>$}]{pgm\+\_\+args }\end{DoxyParamCaption})}



Parses the parameter list according to the option hash passed to the constructor and displays an explanatory error message on stderr and exits the program if an error occurs. 

\begin{DoxyParagraph}{Restrictions\+:}
\mbox{\hyperlink{group__parse__options_ga10d8e3f76c427b0f974529de572dd0ec}{Qore\+::\+P\+O\+\_\+\+N\+O\+\_\+\+P\+R\+O\+C\+E\+S\+S\+\_\+\+C\+O\+N\+T\+R\+OL}}
\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & A list of arguments to process\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument
\end{DoxyReturn}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse3(ARGV);}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyExceptions}{Exceptions}
{\em G\+E\+T\+O\+P\+T-\/\+E\+R\+R\+OR} & error parsing arguments\\
\hline
\end{DoxyExceptions}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{Get\+Opt\+::parse()}} for a similar method that puts error information in the {\ttfamily \char`\"{}\+\_\+\+E\+R\+R\+O\+R\+S\+\_\+\char`\"{}} key of the \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}} value returned
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a206d7279648318593046ddea9385d64f}{Get\+Opt\+::parse2()}} for a similar method that throws exceptions instead of exiting the program 
\end{DoxyItemize}
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_a0623e1c6ad888a7b1ecba22cf9da1db9}\label{class_qore_1_1_get_opt_a0623e1c6ad888a7b1ecba22cf9da1db9}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parseEx@{parseEx}}
\index{parseEx@{parseEx}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parseEx()}{parseEx()}}
{\footnotesize\ttfamily static \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse\+Ex (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$}]{opts,  }\item[{reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$}]{pgm\+\_\+args }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



Parses the given options and returns a hash of the parsed options and throws and exception if there are any errors. 

\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse(\(\backslash\)ARGV);}
\DoxyCodeLine{\textcolor{keywordflow}{if} (exists o.\textcolor{stringliteral}{"\_ERRORS\_"}) \{}
\DoxyCodeLine{    foreach string err \textcolor{keywordflow}{in} (o.\textcolor{stringliteral}{"\_ERRORS\_"})}
\DoxyCodeLine{        stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, err);}
\DoxyCodeLine{    \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & The reference should point to a list of arguments to process (normally {\ttfamily A\+R\+GV}); any argument accepted by the object will be removed from the list\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument. An exception is thrown if there are any errors.
\end{DoxyReturn}
All arguments parsed will be removed from {\itshape pgm\+\_\+args}, leaving only unparsed arguments (for example, file names).

If any errors are encountered, a {\ttfamily G\+E\+T\+O\+P\+T-\/\+E\+R\+R\+OR} exception is thrown.


\begin{DoxyExceptions}{Exceptions}
{\em G\+E\+T\+O\+P\+T-\/\+E\+R\+R\+OR} & error parsing arguments\\
\hline
\end{DoxyExceptions}
\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{Qore\+::\+Get\+Opt\+::parse()}} \char`\"{}\+Get\+Opt\+::parse(hash$<$auto$>$, reference$<$list$<$string$>$$>$)\char`\"{}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_ac7c14bec422068688736aac2557e427b}{Qore\+::\+Get\+Opt\+::parse\+Exit()}} \char`\"{}\+Get\+Opt\+::parse\+Exit(hash$<$auto$>$, reference$<$list$<$string$>$$>$)\char`\"{} 
\end{DoxyItemize}
\end{DoxySeeAlso}
\mbox{\Hypertarget{class_qore_1_1_get_opt_ac7c14bec422068688736aac2557e427b}\label{class_qore_1_1_get_opt_ac7c14bec422068688736aac2557e427b}} 
\index{Qore::GetOpt@{Qore::GetOpt}!parseExit@{parseExit}}
\index{parseExit@{parseExit}!Qore::GetOpt@{Qore::GetOpt}}
\subsubsection{\texorpdfstring{parseExit()}{parseExit()}}
{\footnotesize\ttfamily static \mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$auto$>$ Qore\+::\+Get\+Opt\+::parse\+Exit (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{group__type__conversion__functions_ga0231dbb472dd230310af7c7c34f56e92}{hash}}$<$ auto $>$}]{opts,  }\item[{reference$<$ \mbox{\hyperlink{group__type__conversion__functions_ga4b52a1cbee7a3aed46c32cb0a938629c}{list}}$<$ \mbox{\hyperlink{group__type__conversion__functions_gacf16b4126b795f4b6933ef3425cadae3}{string}} $>$$>$}]{pgm\+\_\+args }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



Parses the given options and returns a hash of the parsed options; prints out an error message and exits the program if there are any errors. 

\begin{DoxyParagraph}{Restrictions\+:}
\mbox{\hyperlink{group__parse__options_ga10d8e3f76c427b0f974529de572dd0ec}{Qore\+::\+P\+O\+\_\+\+N\+O\+\_\+\+P\+R\+O\+C\+E\+S\+S\+\_\+\+C\+O\+N\+T\+R\+OL}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example\+:}

\begin{DoxyCode}{0}
\DoxyCodeLine{hash<auto> o = getopt.parse(\(\backslash\)ARGV);}
\DoxyCodeLine{\textcolor{keywordflow}{if} (exists o.\textcolor{stringliteral}{"\_ERRORS\_"}) \{}
\DoxyCodeLine{    foreach string err \textcolor{keywordflow}{in} (o.\textcolor{stringliteral}{"\_ERRORS\_"})}
\DoxyCodeLine{        stderr.printf(\textcolor{stringliteral}{"\%s\(\backslash\)n"}, err);}
\DoxyCodeLine{    \mbox{\hyperlink{group__library__functions_ga3ec32747f455642fd9ce503094a5cc85}{exit}}(1);}
\DoxyCodeLine{\}}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
{\em pgm\+\_\+args} & The reference should point to a list of arguments to process (normally {\ttfamily A\+R\+GV}); any argument accepted by the object will be removed from the list\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A hash keyed by option names (as given in the hash to the \mbox{\hyperlink{class_qore_1_1_get_opt}{Get\+Opt}} constructor), where each key\textquotesingle{}s value is the value of the argument passed in the list argument. Prints out an error message and exits the program if there are any errors.
\end{DoxyReturn}
All arguments parsed will be removed from {\itshape pgm\+\_\+args}, leaving only unparsed arguments (for example, file names).

\begin{DoxySeeAlso}{See also}

\begin{DoxyItemize}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a54a3b13b00dd1a95f525f03409bca8ee}{Qore\+::\+Get\+Opt\+::parse()}} \char`\"{}\+Get\+Opt\+::parse(hash$<$auto$>$, reference$<$list$<$string$>$$>$)\char`\"{}
\item \mbox{\hyperlink{class_qore_1_1_get_opt_a0623e1c6ad888a7b1ecba22cf9da1db9}{Qore\+::\+Get\+Opt\+::parse\+Ex()}} \char`\"{}\+Get\+Opt\+::parse\+Ex(hash$<$auto$>$, reference$<$list$<$string$>$$>$)\char`\"{} 
\end{DoxyItemize}
\end{DoxySeeAlso}
