Repository navigation
Expand file tree
/
Copy pathcli_value.cpp
More file actions
68 lines (55 loc) · 1.74 KB
/
Copy pathcli_value.cpp
File metadata and controls
68 lines (55 loc) · 1.74 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
#include "cli_value.h"
#include "stdafx.h"
using namespace cli;
uint64_t value_base::ID_GENERATOR {0u};
uint64_t value<bool>::m_ID {value_base::ID_GENERATOR++};
value_base::value_base(psl::string const& name,
psl::string const& cmd,
std::optional<psl::char_t> short_cmd,
std::optional<psl::string> hint,
bool required)
: m_Name(name), m_Cmd(cmd), m_ShortCmd(short_cmd), m_Hint(hint), m_Required(required) {}
psl::string value_base::help(uint32_t indent) const {
psl::string res;
uint64_t cmd_size = ((m_ShortCmd) ? 2u : 0u) + 4 + m_Cmd.size();
res += psl::string(indent * 2, ' ') + m_Name + ((required()) ? "*" : "") +
psl::string(24u - m_Name.size() - (uint64_t)required(), ' ') + "[" +
((m_ShortCmd) ? "-" + psl::string(1u, m_ShortCmd.value()) + ", --" : "--") + m_Cmd + ']' +
psl::string(24 - cmd_size, ' ') + "| " + m_Hint.value_or("") + '\n';
return res;
}
value_base& cli::value_base::required(bool value) {
m_Required = value;
return *this;
}
value_base& cli::value_base::name(psl::string_view value) {
m_Name = value;
return *this;
}
value_base& cli::value_base::command(psl::string_view value) {
m_Cmd = value;
return *this;
}
value_base& cli::value_base::short_command(psl::char_t value) {
m_ShortCmd = value;
return *this;
}
value_base& cli::value_base::hint(psl::string_view value) {
m_Hint = value;
return *this;
}
bool cli::value_base::required() const {
return m_Required;
}
psl::string_view cli::value_base::name() const {
return m_Name;
}
psl::string_view cli::value_base::command() const {
return m_Cmd;
}
std::optional<psl::char_t> cli::value_base::short_command() const {
return m_ShortCmd;
}
std::optional<psl::string_view> cli::value_base::hint() const {
return m_Hint;
}