AppOptions::AppOptions(LPCTSTR pszCommandLine) :m_enStartMode(smInteractive), m_dwAttachProcessId(0) { ProgramOptions opt; ProgramOptions::T_fnOptionHandlerNoArg fnOnParamInteractive = std::bind(&AppOptions::OnParamInteractive, this); opt.RegisterOption(_T("i"), _T("interactive"), _T("Interactive mode (default)"), fnOnParamInteractive); ProgramOptions::T_fnOptionHandlerSingleArg fnOnParamAttach = std::bind(&AppOptions::OnParamAttach, this, std::placeholders::_1); opt.RegisterOption(_T("a"), _T("attach"), _T("Attach to process with pid given in next parameter (pid may be decimal or hex, when prefixed with 0x)"), fnOnParamAttach); ProgramOptions::T_fnOptionHandlerSingleArg fnOnParamStart = std::bind(&AppOptions::OnParamStart, this, std::placeholders::_1); opt.RegisterOption(_T("s"), _T("start"), _T("Start application given in next parameter"), fnOnParamStart); ProgramOptions::T_fnOptionHandlerSingleArg fnOnParamCommandLine = std::bind(&AppOptions::OnParamCommandLine, this, std::placeholders::_1); opt.RegisterOption(_T("c"), _T("command"), _T("Uses command line parameters given in next parameter, when /s is used"), fnOnParamCommandLine); if (_tcslen(pszCommandLine) > 0) opt.Parse(pszCommandLine); }
/// \retval false App should not be started /// \retval true App can be started bool App::ParseCommandLine() { ProgramOptions options; options.RegisterOutputHandler(&ProgramOptions::OutputConsole); options.RegisterHelpOption(); bool bStartApp = true; options.RegisterOption(_T("r"), _T("register-wia"), _T("registers WIA handler for RemotePhotoTool"), 0, [&](const std::vector<CString>&) { RegisterWIAHandler(true); bStartApp = false; return true; }); options.RegisterOption(_T("u"), _T("unregister-wia"), _T("unregisters WIA handler for RemotePhotoTool"), 0, [&](const std::vector<CString>&) { RegisterWIAHandler(false); bStartApp = false; return true; }); options.RegisterOption(_T("o"), _T("open-wia"), _T("opens camera using WIA handler; <arg1>: Port, <arg2>: Guid"), 2, [&](const std::vector<CString>& vecArgs) { vecArgs; ATLASSERT(vecArgs.size() == 2); // just let the app start here return true; }); options.Parse(GetCommandLine()); if (!bStartApp || options.IsSelectedHelpOption()) return false; return true; }