blob: deeb9923abc3a8e5c48e9e2bac5fc318703fc898 (
plain)
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
109
|
#pragma once
#include <vector>
#include <memory>
namespace cl
{
namespace po = boost::program_options;
class Command
{
public:
virtual ~Command() = default;
std::string name() const;
std::string description() const;
po::options_description options() const;
std::string usage() const;
virtual bool allow_unregistered() const;
std::optional<int> run(
const std::wstring& originalLine,
po::variables_map vm,
std::vector<std::wstring> untouched);
protected:
struct Meta
{
std::string name, description;
};
virtual po::options_description doOptions() const;
virtual Meta meta() const = 0;
virtual std::optional<int> doRun() = 0;
const std::wstring& originalCmd() const;
const po::variables_map& vm() const;
const std::vector<std::wstring>& untouched() const;
private:
std::wstring m_original;
po::variables_map m_vm;
std::vector<std::wstring> m_untouched;
};
class CrashDumpCommand : public Command
{
protected:
po::options_description doOptions() const;
Meta meta() const override;
std::optional<int> doRun() override;
};
// this is the `launch` command used when starting a process from within the
// virtualized directory, see processrunner.cpp
//
// it has its own parsing of the command line to extract the argument after
// `launch` and use it as the cwd of the process, but pass the remaining
// arguments verbatim
//
// this is very old code that should probably never be changed
//
// note that it's actually buggy; in particular, it doesn't handle multiple
// whitespace between arguments
//
class LaunchCommand : public Command
{
public:
bool allow_unregistered() const override;
protected:
po::options_description doOptions() const;
Meta meta() const override;
std::optional<int> doRun() override;
int SpawnWaitProcess(LPCWSTR workingDirectory, LPCWSTR commandLine);
LPCWSTR UntouchedCommandLineArguments(
int parseArgCount, std::vector<std::wstring>& parsedArgs);
};
class CommandLine
{
public:
CommandLine();
std::optional<int> run(const std::wstring& line);
std::string usage(const Command* c=nullptr) const;
bool multiple() const;
private:
po::options_description m_visibleOptions, m_allOptions;
po::positional_options_description m_positional;
std::vector<std::unique_ptr<Command>> m_commands;
po::variables_map m_vm;
void createOptions();
std::string more() const;
};
} // namespace
|