MemoryAccessor 1
A command-line front-end for exploring virtual memory of a linux process by accessing /proc/PID/mem file.
Loading...
Searching...
No Matches
argvparser.h
Go to the documentation of this file.
1// MemoryAccessor - A tool for accessing /proc/PID/mem
2// Copyright (C) 2024 zloymish
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
24#ifndef MEMORYACCESSOR_SRC_ARGVPARSER_H_
25#define MEMORYACCESSOR_SRC_ARGVPARSER_H_
26
27#include <array>
28#include <map>
29#include <string>
30#include <vector>
31
32#include "console.h"
33
41public:
48 explicit ArgvParser(Console &console) noexcept : console_(console) {}
49
50 void ParseArgv(const int &argc, char **argv) noexcept;
51
52private:
53 using KeyFuncP = void (ArgvParser::*)(
54 const int &argc, char **argv);
55
56 void Usage() const noexcept;
57 void PrintErrPrefix() const noexcept;
58 void TypeHelp() const noexcept;
59 void ArgReq(const std::string &key) const noexcept;
60 void ArgUnkn(const std::string &key) const noexcept;
61 void FileNotEx(const std::string &path) const noexcept;
62 void FileErr(const std::string &path) const noexcept;
63
64 void KeyHelp(const int &argc, char **argv) noexcept;
65 void KeyCommand(const int &argc, char **argv) noexcept;
66 void KeyFile(const int &argc, char **argv) noexcept;
67
68 Console &console_;
69 const std::vector<std::array<std::string, 2>> kKeyManuals{
70 {"--help", "show help"},
71 {"--command COMMAND", "do command"},
72 {"--file FILE", "do commands from file"},
73 };
75 const std::map<std::string, KeyFuncP> kKeys{
76 {"--help", &ArgvParser::KeyHelp},
77 {"--command", &ArgvParser::KeyCommand},
78 {"--file", &ArgvParser::KeyFile},
79 };
80};
81
82#endif // MEMORYACCESSOR_SRC_ARGVPARSER_H_
A class to parse arguments from the command line.
Definition argvparser.h:40
void ParseArgv(const int &argc, char **argv) noexcept
Parse program arguments.
Definition argvparser.cc:45
ArgvParser(Console &console) noexcept
Constructor.
Definition argvparser.h:48
A class to perform CLI.
Definition console.h:68
Console and Command header.