34 std::string host =
"localhost";
38 for (
size_t i = 0; i < args.size(); ++i) {
39 if (args[i] ==
"--host" && i + 1 < args.size()) {
42 }
else if (args[i] ==
"--port" && i + 1 < args.size()) {
43 port = std::stoi(args[i + 1]);
48 std::cout <<
"Connecting to " << host <<
":" << port <<
"..." << std::endl;
50 auto status = g_network_client->Connect(host, port);
53 std::cout <<
"✓ Connected to yaze-server" << std::endl;
55 std::cerr <<
"✗ Connection failed: " << status.message() << std::endl;
64 if (!g_network_client->IsConnected()) {
65 return absl::FailedPreconditionError(
66 "Not connected. Run: z3ed net connect");
69 std::string session_code;
73 for (
size_t i = 0; i < args.size(); ++i) {
74 if (args[i] ==
"--code" && i + 1 < args.size()) {
75 session_code = args[i + 1];
77 }
else if (args[i] ==
"--username" && i + 1 < args.size()) {
78 username = args[i + 1];
83 if (session_code.empty() || username.empty()) {
84 return absl::InvalidArgumentError(
85 "Usage: z3ed net join --code <CODE> --username <NAME>");
88 std::cout <<
"Joining session " << session_code <<
" as " << username <<
"..."
91 auto status = g_network_client->JoinSession(session_code, username);
94 std::cout <<
"✓ Joined session successfully" << std::endl;
96 std::cerr <<
"✗ Failed to join: " << status.message() << std::endl;
121 if (!g_network_client->IsConnected()) {
122 return absl::FailedPreconditionError(
123 "Not connected. Run: z3ed net connect");
127 std::cout <<
"Usage:\n";
129 <<
" z3ed net proposal submit --description <DESC> --data <JSON>\n";
130 std::cout <<
" z3ed net proposal status --id <ID>\n";
131 std::cout <<
" z3ed net proposal wait --id <ID> [--timeout <SEC>]\n";
132 return absl::OkStatus();
135 std::string subcommand = args[0];
136 std::vector<std::string> subargs(args.begin() + 1, args.end());
138 if (subcommand ==
"submit") {
140 }
else if (subcommand ==
"status") {
142 }
else if (subcommand ==
"wait") {
145 return absl::InvalidArgumentError(
146 absl::StrFormat(
"Unknown proposal subcommand: %s", subcommand));
151 std::string description;
152 std::string data_json;
153 std::string username =
"cli_user";
155 for (
size_t i = 0; i < args.size(); ++i) {
156 if (args[i] ==
"--description" && i + 1 < args.size()) {
157 description = args[i + 1];
159 }
else if (args[i] ==
"--data" && i + 1 < args.size()) {
160 data_json = args[i + 1];
162 }
else if (args[i] ==
"--username" && i + 1 < args.size()) {
163 username = args[i + 1];
168 if (description.empty() || data_json.empty()) {
169 return absl::InvalidArgumentError(
170 "Usage: z3ed net proposal submit --description <DESC> --data <JSON>");
173 std::cout <<
"Submitting proposal..." << std::endl;
174 std::cout <<
" Description: " << description << std::endl;
177 g_network_client->SubmitProposal(description, data_json, username);
180 std::cout <<
"✓ Proposal submitted" << std::endl;
181 std::cout <<
" Waiting for approval from host..." << std::endl;
183 std::cerr <<
"✗ Failed to submit: " << status.message() << std::endl;
190 std::string proposal_id;
192 for (
size_t i = 0; i < args.size(); ++i) {
193 if (args[i] ==
"--id" && i + 1 < args.size()) {
194 proposal_id = args[i + 1];
199 if (proposal_id.empty()) {
200 return absl::InvalidArgumentError(
201 "Usage: z3ed net proposal status --id <ID>");
204 auto status_result = g_network_client->GetProposalStatus(proposal_id);
206 if (status_result.ok()) {
207 std::cout <<
"Proposal " << proposal_id.substr(0, 8) <<
"..." << std::endl;
208 std::cout <<
" Status: " << *status_result << std::endl;
210 std::cerr <<
"✗ Failed to get status: " << status_result.status().message()
214 return status_result.status();
218 std::string proposal_id;
219 int timeout_seconds = 60;
221 for (
size_t i = 0; i < args.size(); ++i) {
222 if (args[i] ==
"--id" && i + 1 < args.size()) {
223 proposal_id = args[i + 1];
225 }
else if (args[i] ==
"--timeout" && i + 1 < args.size()) {
226 timeout_seconds = std::stoi(args[i + 1]);
231 if (proposal_id.empty()) {
232 return absl::InvalidArgumentError(
233 "Usage: z3ed net proposal wait --id <ID> [--timeout <SEC>]");
236 std::cout <<
"Waiting for approval (timeout: " << timeout_seconds <<
"s)..."
239 auto approved_result =
240 g_network_client->WaitForApproval(proposal_id, timeout_seconds);
242 if (approved_result.ok()) {
243 if (*approved_result) {
244 std::cout <<
"✓ Proposal approved!" << std::endl;
246 std::cout <<
"✗ Proposal rejected" << std::endl;
249 std::cerr <<
"✗ Error: " << approved_result.status().message() << std::endl;
252 return approved_result.status();