-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinput.cpp
More file actions
108 lines (92 loc) · 2.08 KB
/
Copy pathinput.cpp
File metadata and controls
108 lines (92 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "include/console/input.h"
#include <iostream>
using namespace Console;
/**
* Initialize the application interface.
*
* @param Interfaces::ApplicationInterface * app
*/
Input::Input(Interfaces::ApplicationInterface* app) noexcept { m_app = app; }
/**
* Retrieve an input from the user.
*
* @param const std::string & question
* @return std::string
*/
std::string Input::ask(const std::string& question) noexcept
{
std::cout << question << '\n';
std::string input;
std::cin >> input;
return input;
}
/**
* Retrieve the parsed options.
*
* @return Options
*/
Types::Options Input::getOptions() noexcept { return m_options; }
/**
* Setter for the parsed options.
*
* @return Types::Options options
* @return void
*/
void Input::setOptions(Types::Options options) noexcept { m_options = std::move(options); }
/**
* Determine if the -h or --help flag
* was supplied.
*
* @return bool
*/
bool Input::wantsHelp() noexcept
{
for (auto& option : getOptions())
{
if (option.first == "h" || option.second.first == "help")
return true;
}
return false;
}
/**
* Retrieve the option value
* by given option.
*
* @param const std::string & option
* @return std::string
*/
std::string Input::getOption(const std::string& option) noexcept
{
for (auto& availableOption : getOptions())
{
if (availableOption.second.first == option)
return availableOption.second.second;
}
return "";
}
/**
* Retrieve the option value
* by given option and alias.
*
* @param const std::string & option
* @param const std::string & alias
* @return std::string
*/
std::string Input::getOption(const std::string& option, const std::string& alias) noexcept
{
for (auto& availableOption : getOptions())
{
if (availableOption.first == alias || availableOption.second.first == option)
return availableOption.second.second;
}
return "";
}
/**
* Retrieve the first positional argument.
*
* @return std::string
*/
std::string Input::getArgument() noexcept
{
return getOption("argument");
}