#include "wx/string.h"
#include "wx/log.h"
#include "wx/intl.h"
+ #include "wx/app.h"
#include "wx/dynarray.h"
+ #include "wx/filefn.h"
#endif //WX_PRECOMP
+#include <ctype.h>
+
#include "wx/datetime.h"
#include "wx/cmdline.h"
// types increases, so always use the accessor functions and don't access
// the fields directly!)
- void Check(wxCmdLineParamType typ) const
+ void Check(wxCmdLineParamType WXUNUSED_UNLESS_DEBUG(typ)) const
{
wxASSERT_MSG( type == typ, _T("type mismatch in wxCmdLineOption") );
}
{
// options
wxString m_switchChars; // characters which may start an option
-
bool m_enableLongOptions; // TRUE if long options are enabled
+ wxString m_logo; // some extra text to show in Usage()
// cmd line data
wxArrayString m_arguments; // == argv, argc == m_arguments.GetCount()
}
}
-void wxCmdLineParserData::SetArguments(const wxString& cmdline)
+void wxCmdLineParserData::SetArguments(const wxString& WXUNUSED(cmdline))
{
// either use wxMSW wxApp::ConvertToStandardCommandArgs() or move its logic
// here and use this method from it - but don't duplicate the code
m_data->m_enableLongOptions = enable;
}
+void wxCmdLineParser::SetLogo(const wxString& logo)
+{
+ m_data->m_logo = logo;
+}
+
// ----------------------------------------------------------------------------
// command line construction
// ----------------------------------------------------------------------------
switch ( desc->kind )
{
case wxCMD_LINE_SWITCH:
- AddSwitch(desc->shortName, desc->longName, desc->description);
+ AddSwitch(desc->shortName, desc->longName, desc->description,
+ desc->flags);
break;
case wxCMD_LINE_OPTION:
}
while ( optInd == wxNOT_FOUND );
+ len++; // compensates extra len-- above
if ( (optInd != wxNOT_FOUND) && (len != name.length()) )
{
+ // first of all, the option name is only part of this
+ // string
+ name = name.Left(len);
+
// our option is only part of this argument, there is
// something else in it - it is either the value of this
// option or other switches if it is a switch
// pretend that all the rest of the argument is the
// next argument, in fact
wxString arg2 = arg[0u];
- arg2 += name.Mid(len + 1); // compensates extra --
+ arg2 += arg.Mid(len + 1); // +1 for leading '-'
m_data->m_arguments.Insert(arg2, n + 1);
count++;
const wxChar *res = dt.ParseDate(value);
if ( !res || *res )
{
- wxLogError(_("Options '%s': '%s' cannot "
+ wxLogError(_("Option '%s': '%s' cannot "
"be converted to a date."),
name.c_str(), value.c_str());
void wxCmdLineParser::Usage()
{
+ wxString appname = wxTheApp->GetAppName();
+ if ( !appname )
+ {
+ wxCHECK_RET( !m_data->m_arguments.IsEmpty(), _T("no program name") );
+
+ appname = wxFileNameFromPath(m_data->m_arguments[0]);
+ wxStripExtension(appname);
+ }
+
wxString brief, detailed;
- brief.Printf(_("Usage: %s"), wxTheApp->GetAppName().c_str());
+ brief.Printf(_("Usage: %s"), appname.c_str());
size_t n, count = m_data->m_options.GetCount();
for ( n = 0; n < count; n++ )
}
}
+ if ( !!m_data->m_logo )
+ {
+ wxLogMessage(m_data->m_logo);
+ }
+
wxLogMessage(brief);
wxLogMessage(detailed);
}