-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeployCommand.cpp
More file actions
143 lines (126 loc) · 3.8 KB
/
Copy pathDeployCommand.cpp
File metadata and controls
143 lines (126 loc) · 3.8 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
*
* @file DeployCommand.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*/
#include <vix/cli/commands/DeployCommand.hpp>
#include <vix/cli/commands/deploy/DeployConfig.hpp>
#include <vix/cli/commands/deploy/DeployOutput.hpp>
#include <vix/cli/commands/deploy/DeployRunner.hpp>
#include <vix/cli/commands/deploy/DeployTypes.hpp>
#include <iostream>
#include <string>
#include <vector>
namespace vix::commands
{
namespace
{
#ifdef __linux__
bool consume_flag(
std::vector<std::string> &args,
const std::string &flag)
{
for (auto it = args.begin(); it != args.end(); ++it)
{
if (*it == flag)
{
args.erase(it);
return true;
}
}
return false;
}
deploy::DeployOptions parse_options(
std::vector<std::string> &args)
{
deploy::DeployOptions options;
options.dryRun = consume_flag(args, "--dry-run");
options.verbose = consume_flag(args, "--verbose") ||
consume_flag(args, "-v");
options.noPull = consume_flag(args, "--no-pull");
options.noTests = consume_flag(args, "--no-tests");
return options;
}
#endif
}
int DeployCommand::run(const std::vector<std::string> &argsIn)
{
#ifndef __linux__
(void)argsIn;
deploy::output::error(
std::cerr,
"vix deploy is currently supported on Linux only.");
return 1;
#else
std::vector<std::string> args = argsIn;
if (!args.empty() &&
(args[0] == "-h" || args[0] == "--help"))
{
return help();
}
deploy::DeployOptions options = parse_options(args);
if (!args.empty())
{
deploy::output::error(
std::cerr,
"unknown deploy argument: " + args[0]);
deploy::output::fix(
std::cerr,
"vix deploy --help");
return 1;
}
deploy::DeployConfig cfg =
deploy::apply_deploy_options(
deploy::load_deploy_config(),
options);
return deploy::runner::run(cfg, options);
#endif
}
int DeployCommand::help()
{
std::cout
<< "Usage:\n"
<< " vix deploy [options]\n\n"
<< "Options:\n"
<< " --dry-run Print deployment steps without executing them\n"
<< " --verbose Print additional execution details\n"
<< " -v Alias for --verbose\n"
<< " --no-pull Skip git pull even when enabled in vix.json\n"
<< " --no-tests Skip tests even when enabled in vix.json\n"
<< " -h, --help Show this help message\n\n"
<< "Examples:\n"
<< " vix deploy\n"
<< " vix deploy --dry-run\n"
<< " vix deploy --no-pull\n"
<< " vix deploy --verbose\n\n"
<< "Config:\n"
<< " production.deploy.pull\n"
<< " production.deploy.branch\n"
<< " production.deploy.build\n"
<< " production.deploy.tests\n"
<< " production.deploy.test_command\n"
<< " production.deploy.service\n"
<< " production.deploy.health_local\n"
<< " production.deploy.health_public\n"
<< " production.deploy.proxy_check\n"
<< " production.deploy.proxy_reload\n"
<< " production.deploy.logs_on_failure\n"
<< " production.deploy.log_lines\n"
<< " production.deploy.rollback\n"
<< " production.health.service\n"
<< " production.health.local\n"
<< " production.health.public\n"
<< " production.health.websocket\n"
<< " production.logs.service\n"
<< " production.logs.nginx_access\n"
<< " production.logs.nginx_error\n";
return 0;
}
}