Blame cli/cmdlineparser.h

Packit 2035a7
/*
Packit 2035a7
 * Cppcheck - A tool for static C/C++ code analysis
Packit 2035a7
 * Copyright (C) 2007-2017 Cppcheck team.
Packit 2035a7
 *
Packit 2035a7
 * This program is free software: you can redistribute it and/or modify
Packit 2035a7
 * it under the terms of the GNU General Public License as published by
Packit 2035a7
 * the Free Software Foundation, either version 3 of the License, or
Packit 2035a7
 * (at your option) any later version.
Packit 2035a7
 *
Packit 2035a7
 * This program is distributed in the hope that it will be useful,
Packit 2035a7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 2035a7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 2035a7
 * GNU General Public License for more details.
Packit 2035a7
 *
Packit 2035a7
 * You should have received a copy of the GNU General Public License
Packit 2035a7
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 2035a7
 */
Packit 2035a7
Packit 2035a7
#ifndef CMDLINE_PARSER_H
Packit 2035a7
#define CMDLINE_PARSER_H
Packit 2035a7
Packit 2035a7
#include <string>
Packit 2035a7
#include <vector>
Packit 2035a7
Packit 2035a7
class Settings;
Packit 2035a7
Packit 2035a7
/// @addtogroup CLI
Packit 2035a7
/// @{
Packit 2035a7
Packit 2035a7
/**
Packit 2035a7
 * @brief The command line parser.
Packit 2035a7
 * The command line parser parses options and parameters user gives to
Packit 2035a7
 * cppcheck command line.
Packit 2035a7
 *
Packit 2035a7
 * The parser takes a pointer to Settings instance which it will update
Packit 2035a7
 * based on options user has given. Couple of options are handled as
Packit 2035a7
 * class internal options.
Packit 2035a7
 */
Packit 2035a7
class CmdLineParser {
Packit 2035a7
public:
Packit 2035a7
    /**
Packit 2035a7
     * The constructor.
Packit 2035a7
     * @param settings Settings instance that will be modified according to
Packit 2035a7
     * options user has given.
Packit 2035a7
     */
Packit 2035a7
    explicit CmdLineParser(Settings *settings);
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Parse given command line.
Packit 2035a7
     * @return true if command line was ok, false if there was an error.
Packit 2035a7
     */
Packit 2035a7
    bool ParseFromArgs(int argc, const char* const argv[]);
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Return if user wanted to see program version.
Packit 2035a7
     */
Packit 2035a7
    bool GetShowVersion() const {
Packit 2035a7
        return _showVersion;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Return if user wanted to see list of error messages.
Packit 2035a7
     */
Packit 2035a7
    bool GetShowErrorMessages() const {
Packit 2035a7
        return _showErrorMessages;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Return the path names user gave to command line.
Packit 2035a7
     */
Packit 2035a7
    const std::vector<std::string>& GetPathNames() const {
Packit 2035a7
        return _pathnames;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Return if help is shown to user.
Packit 2035a7
     */
Packit 2035a7
    bool GetShowHelp() const {
Packit 2035a7
        return _showHelp;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Return if we should exit after printing version, help etc.
Packit 2035a7
     */
Packit 2035a7
    bool ExitAfterPrinting() const {
Packit 2035a7
        return _exitAfterPrint;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Return a list of paths user wants to ignore.
Packit 2035a7
     */
Packit 2035a7
    const std::vector<std::string>& GetIgnoredPaths() const {
Packit 2035a7
        return _ignoredPaths;
Packit 2035a7
    }
Packit 2035a7
Packit 2035a7
protected:
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Print help text to the console.
Packit 2035a7
     */
Packit 2035a7
    static void PrintHelp();
Packit 2035a7
Packit 2035a7
    /**
Packit 2035a7
     * Print message (to console?).
Packit 2035a7
     */
Packit 2035a7
    static void PrintMessage(const std::string &message);
Packit 2035a7
    static void PrintMessage(const char* message);
Packit 2035a7
Packit 2035a7
private:
Packit 2035a7
    std::vector<std::string> _pathnames;
Packit 2035a7
    std::vector<std::string> _ignoredPaths;
Packit 2035a7
    Settings *_settings;
Packit 2035a7
    bool _showHelp;
Packit 2035a7
    bool _showVersion;
Packit 2035a7
    bool _showErrorMessages;
Packit 2035a7
    bool _exitAfterPrint;
Packit 2035a7
};
Packit 2035a7
Packit 2035a7
/// @}
Packit 2035a7
Packit 2035a7
#endif // CMDLINE_PARSER_H