Skip to content

Commit 55ef8fd

Browse files
committed
Merge branch 'devel-0.0.1'
2 parents 6ff143d + f3dc7ae commit 55ef8fd

5 files changed

Lines changed: 460 additions & 360 deletions

File tree

server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ proto = { path = "../proto", version = "0.1.0", features = ["server"] }
7373
models = { path = "../models", version = "0.1.0" }
7474
reqwest = { version = "0.12.22", features = ["json"] }
7575
shell-words="1.1.0"
76+
shlex="1.3.0"
7677

7778
[dev-dependencies]
7879
serde_json = "1.0.140"

server/src/cli/cli.rs

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
// server/src/cli/cli.rs
2+
// Refactored: 2025-07-04 - Updated to use new storage engine names and removed obsolete imports.
3+
// Fixed: 2025-07-04 - Corrected argument types for handle_restart_command_interactive.
4+
// Fixed: 2025-07-04 - Corrected function name for run_cli_interactive.
5+
// Fixed: 2025-07-04 - Resolved Mutex type mismatches and argument wrapping for handlers.
6+
// Reverted: 2025-07-04 - Reverted to user-provided base code structure, re-applying necessary fixes.
7+
// Fixed: 2025-07-04 - Corrected argument count for run_cli_interactive calls.
8+
// FIX: 2025-07-04 - Removed #[tokio::main] from start_cli to resolve E0277.
9+
// FIX: 2025-07-04 - Corrected argument count for handle_reload_command and run_cli_interactive calls.
10+
// UPDATED: 2025-07-04 - Added Clear, Exit, Quit commands. Corrected run_cli_interactive argument passing.
11+
// UPDATED: 2025-07-04 - Removed duplicate HelpArgs struct, now relying on import.
12+
// FIX: 2025-07-04 - Corrected import path for `handle_internal_daemon_run`.
213

3-
use anyhow::Result;
414
use clap::{Parser, Subcommand, CommandFactory};
5-
use std::collections::HashMap;
15+
use anyhow::Result;
616
use std::path::PathBuf;
717
use std::sync::Arc;
8-
use tokio::sync::{oneshot, Mutex};
18+
use tokio::sync::Mutex;
19+
use tokio::sync::oneshot;
920
use tokio::task::JoinHandle;
1021
use std::process;
1122
use std::env;
23+
use std::collections::HashMap;
1224

1325
// Import modules
1426
use crate::cli::commands::{
1527
DaemonCliCommand, RestCliCommand, StorageAction,
1628
StatusArgs, StopArgs, ReloadArgs, RestartArgs,
1729
ReloadAction, RestartAction, StartAction, StopAction, StatusAction
1830
};
19-
use crate::cli::config as config_mod; // Alias for config module
31+
use crate::cli::config as config_mod;
2032
use crate::cli::handlers as handlers_mod;
2133
use crate::cli::interactive as interactive_mod;
22-
use crate::cli::help_display as help_display_mod; // Alias the module directly
23-
use crate::cli::daemon_management::handle_internal_daemon_run; // Corrected: Imported directly
34+
use crate::cli::help_display as help_display_mod;
35+
use crate::cli::daemon_management::handle_internal_daemon_run; // DIRECT IMPORT for handle_internal_daemon_run
2436

2537
use lib::query_parser::{parse_query_from_string, QueryType};
26-
// Removed unused import: use lib::storage_engine::config::StorageEngineType as LibStorageEngineType;
2738

2839
/// GraphDB Command Line Interface
2940
#[derive(Parser, Debug)]
@@ -62,11 +73,9 @@ pub enum Commands {
6273
Start {
6374
#[clap(subcommand)]
6475
action: Option<StartAction>,
65-
// Removed top-level port, cluster, listen_port, storage_port, storage_config_file
66-
// These are now only available within StartAction::All
6776
},
6877
/// Stop GraphDB components (daemon, rest, storage, or all)
69-
Stop(StopArgs), // Corrected: Changed to directly use StopArgs
78+
Stop(StopArgs),
7079
/// Get status of GraphDB components (daemon, rest, storage, cluster, or all)
7180
Status(StatusArgs),
7281
/// Manage GraphDB daemon instances
@@ -104,26 +113,19 @@ pub enum Commands {
104113
/// Perform a health check on the REST API server
105114
Health,
106115
/// Display help message
107-
Help(HelpArgs),
108-
// Added missing top-level commands to the Commands enum definition
109-
// These were missing from the enum definition but present in the match arm
110-
// No explicit variants needed for Clear/Clean as they are not top-level subcommands
111-
}
112-
113-
#[derive(Parser, Debug)]
114-
pub struct HelpArgs {
115-
/// Filter help for a specific command (e.g., "start daemon")
116-
#[clap(long, short = 'c')]
117-
pub filter_command: Option<String>,
118-
/// Positional arguments for the command path (e.g., "start", "daemon")
119-
pub command_path: Vec<String>,
116+
Help(help_display_mod::HelpArgs),
117+
/// Clear the terminal screen
118+
Clear,
119+
/// Exit the CLI
120+
Exit,
121+
/// Quit the CLI (alias for 'exit')
122+
Quit,
120123
}
121124

122125
/// Main entry point for CLI command handling.
123126
///
124127
/// This function dispatches commands based on `CliArgs` and manages the lifecycle
125128
/// of daemon and REST API processes.
126-
#[tokio::main]
127129
pub async fn start_cli() -> Result<()> {
128130
// --- Custom Help Command Handling ---
129131
let args_vec: Vec<String> = env::args().collect();
@@ -147,10 +149,11 @@ pub async fn start_cli() -> Result<()> {
147149
se_cli.into()
148150
});
149151

152+
// Call directly from daemon_management
150153
return handle_internal_daemon_run(
151154
args.internal_rest_api_run,
152155
args.internal_storage_daemon_run,
153-
args.internal_port, // Corrected: Pass Option<u16> directly
156+
args.internal_port,
154157
args.internal_storage_config_path,
155158
converted_storage_engine,
156159
).await;
@@ -189,6 +192,7 @@ pub async fn start_cli() -> Result<()> {
189192
let rest_api_handle: Arc<Mutex<Option<JoinHandle<()>>>> = Arc::new(Mutex::new(None));
190193
let storage_daemon_shutdown_tx_opt: Arc<Mutex<Option<oneshot::Sender<()>>>> = Arc::new(Mutex::new(None));
191194
let storage_daemon_handle: Arc<Mutex<Option<JoinHandle<()>>>> = Arc::new(Mutex::new(None));
195+
let storage_daemon_port_arc: Arc<Mutex<Option<u16>>> = Arc::new(Mutex::new(None));
192196

193197
let should_enter_interactive_mode = args.cli || args.command.is_none();
194198

@@ -197,14 +201,14 @@ pub async fn start_cli() -> Result<()> {
197201
println!("Experimental plugins are enabled.");
198202
}
199203
match command {
200-
// Updated Commands::Start to only have 'action'
201-
Commands::Start { action } => { // Removed port, cluster, listen_port, storage_port, storage_config_file
204+
Commands::Start { action } => {
202205
match action {
203206
Some(StartAction::All { port, cluster, listen_port, storage_port, storage_config_file }) => {
204207
handlers_mod::handle_start_all_interactive(
205208
port, cluster, listen_port, storage_port, storage_config_file,
206209
daemon_handles.clone(), rest_api_shutdown_tx_opt.clone(), rest_api_port_arc.clone(), rest_api_handle.clone(),
207210
storage_daemon_shutdown_tx_opt.clone(), storage_daemon_handle.clone(),
211+
storage_daemon_port_arc.clone(),
208212
).await?;
209213
}
210214
Some(StartAction::Daemon { port, cluster }) => {
@@ -213,30 +217,28 @@ pub async fn start_cli() -> Result<()> {
213217
daemon_handles.clone(),
214218
).await?;
215219
}
216-
// FIX: Updated StartAction::Rest destructuring and call to match commands.rs
217-
Some(StartAction::Rest { port: rest_start_port }) => { // 'port' is now the listen-port
220+
Some(StartAction::Rest { port: rest_start_port }) => {
218221
handlers_mod::handle_rest_command_interactive(
219-
// Pass the 'port' argument as the single port for RestCliCommand::Start
220222
RestCliCommand::Start { port: rest_start_port },
221223
rest_api_shutdown_tx_opt.clone(),
222224
rest_api_port_arc.clone(),
223225
rest_api_handle.clone(),
224226
).await?;
225227
}
226-
// FIX: Updated StartAction::Storage destructuring to use `port`
227-
Some(StartAction::Storage { port, config_file: storage_start_config_file }) => { // Corrected: Destructure `port`
228+
Some(StartAction::Storage { port, config_file: storage_start_config_file }) => {
228229
handlers_mod::handle_storage_command_interactive(
229-
StorageAction::Start { port, config_file: storage_start_config_file }, // FIX: Pass `port`
230+
StorageAction::Start { port, config_file: storage_start_config_file },
230231
storage_daemon_shutdown_tx_opt.clone(),
231232
storage_daemon_handle.clone(),
233+
storage_daemon_port_arc.clone(),
232234
).await?;
233235
}
234236
None => {
235-
// Default `start` command now implies `start all` without specific args
236237
handlers_mod::handle_start_all_interactive(
237-
None, None, None, None, None, // Pass None for all options
238+
None, None, None, None, None,
238239
daemon_handles.clone(), rest_api_shutdown_tx_opt.clone(), rest_api_port_arc.clone(), rest_api_handle.clone(),
239240
storage_daemon_shutdown_tx_opt.clone(), storage_daemon_handle.clone(),
241+
storage_daemon_port_arc.clone(),
240242
).await?;
241243
}
242244
}
@@ -245,7 +247,11 @@ pub async fn start_cli() -> Result<()> {
245247
handlers_mod::handle_stop_command(stop_args).await?;
246248
}
247249
Commands::Status(status_args) => {
248-
handlers_mod::handle_status_command(status_args, rest_api_port_arc.clone()).await?;
250+
handlers_mod::handle_status_command(
251+
status_args,
252+
rest_api_port_arc.clone(),
253+
storage_daemon_port_arc.clone(),
254+
).await?;
249255
}
250256
Commands::Reload(reload_args) => {
251257
handlers_mod::handle_reload_command(reload_args).await?;
@@ -259,13 +265,15 @@ pub async fn start_cli() -> Result<()> {
259265
rest_api_handle.clone(),
260266
storage_daemon_shutdown_tx_opt.clone(),
261267
storage_daemon_handle.clone(),
268+
storage_daemon_port_arc.clone(),
262269
).await?;
263270
}
264271
Commands::Storage(storage_action) => {
265272
handlers_mod::handle_storage_command_interactive(
266273
storage_action,
267274
storage_daemon_shutdown_tx_opt.clone(),
268275
storage_daemon_handle.clone(),
276+
storage_daemon_port_arc.clone(),
269277
).await?;
270278
}
271279
Commands::Daemon(daemon_cmd) => {
@@ -287,6 +295,7 @@ pub async fn start_cli() -> Result<()> {
287295
rest_api_handle,
288296
storage_daemon_shutdown_tx_opt,
289297
storage_daemon_handle,
298+
storage_daemon_port_arc,
290299
).await?;
291300
}
292301
Commands::Help(help_args) => {
@@ -315,6 +324,14 @@ pub async fn start_cli() -> Result<()> {
315324
Commands::Health => {
316325
handlers_mod::display_rest_api_health().await;
317326
}
327+
Commands::Clear => {
328+
handlers_mod::clear_terminal_screen().await?;
329+
handlers_mod::print_welcome_screen();
330+
}
331+
Commands::Exit | Commands::Quit => {
332+
println!("Exiting CLI. Goodbye!");
333+
process::exit(0);
334+
}
318335
}
319336
return Ok(());
320337
}
@@ -330,6 +347,7 @@ pub async fn start_cli() -> Result<()> {
330347
rest_api_handle,
331348
storage_daemon_shutdown_tx_opt,
332349
storage_daemon_handle,
350+
storage_daemon_port_arc,
333351
).await?;
334352
} else if args.enable_plugins {
335353
println!("Experimental plugins is enabled.");

0 commit comments

Comments
 (0)