-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from jabibamman/feat/cli
Feat - first cli basic implementation
- Loading branch information
Showing
14 changed files
with
118 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ members = [ | |
"shared", | ||
"server", | ||
"complex", | ||
"cli" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["James <jabib@myges.fr>", "Ronan <rkielt@myges.fr>", "Charles <ccretois@myges.fr>", "Samira <sseddar@myges.fr>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.4.6", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pub use clap::Parser; | ||
|
||
/// # Command line arguments for the CLI | ||
/// | ||
/// > This struct is used to parse the command line arguments | ||
/// | ||
/// ## Example | ||
/// | ||
/// ```sh | ||
/// worker -H 192.168.1.0 -P 3000 -N my_group_name | ||
/// ``` | ||
#[derive(Parser, Debug)] | ||
pub struct CliArgs { | ||
#[clap(short = 'H', long = "hostname", default_value = "localhost")] | ||
pub hostname: String, | ||
|
||
#[clap(short = 'P', long = "port", default_value = "8787")] | ||
pub port: u16, | ||
|
||
#[clap(short = 'N', long = "name", default_value = "worker")] | ||
pub worker_name: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod client; | ||
pub mod image; | ||
pub mod julia; | ||
pub mod networking; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod connect; | ||
pub mod reader; | ||
pub mod write; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::{io::Read, net::TcpStream}; | ||
|
||
/// Read a message from a TCP stream. | ||
/// | ||
/// This function reads data from the given TCP stream up to 1024 bytes. | ||
/// It assumes that the message is UTF-8 encoded. If the message contains | ||
/// non-UTF-8 bytes, they will be replaced by U+FFFD REPLACEMENT CHARACTER. | ||
/// The function also trims null characters from the message. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `stream` - A mutable reference to the TCP stream from which to read the message. | ||
/// | ||
/// # Returns | ||
/// | ||
/// Returns a `String` containing the message read from the stream. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// use std::net::{TcpListener, TcpStream}; | ||
/// use server::services::reader::read_message; | ||
/// | ||
/// let listener = TcpListener::bind("127.0.0.1:0").unwrap(); | ||
/// let address = listener.local_addr().unwrap(); | ||
/// let mut stream = TcpStream::connect(address).unwrap(); | ||
/// | ||
/// let message = read_message(stream); | ||
/// println!("Received message: {}", message); | ||
/// ``` | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if the reading from the stream fails or if the buffer cannot be | ||
/// converted to a UTF-8 string. | ||
/// | ||
pub fn read_message(mut stream: TcpStream) -> String { | ||
let mut buffer = [0; 1024]; | ||
stream.read(&mut buffer).unwrap(); | ||
|
||
let message = String::from_utf8_lossy(&buffer[..]); | ||
let message = message.trim_matches(char::from(0)).to_string(); | ||
|
||
message | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters