Skip to content

Commit

Permalink
Restyle Feat - first cli basic implementation (#35)
Browse files Browse the repository at this point in the history
* Restyled by rustfmt

* Restyled by whitespace

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
restyled-io[bot] and restyled-commits authored Nov 16, 2023
1 parent e44c2ff commit 19d1100
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ authors = ["James <jabib@myges.fr>", "Ronan <rkielt@myges.fr>", "Charles <ccreto
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.4.6", features = ["derive"] }
clap = { version = "4.4.6", features = ["derive"] }
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod parser;
pub mod parser;
27 changes: 7 additions & 20 deletions cli/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,35 +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"
)]
#[clap(short = 'H', long = "hostname", default_value = "localhost")]
pub hostname: String,

#[clap(
short = 'P',
long = "port",
default_value = "8787"
)]
#[clap(short = 'P', long = "port", default_value = "8787")]
pub port: u16,

#[clap(
short = 'N',
long = "name",
default_value = "worker"
)]
#[clap(short = 'N', long = "name", default_value = "worker")]
pub worker_name: String,
}
}
7 changes: 3 additions & 4 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::io;
use crate::image::open_image;
use crate::julia::generate_julia_set;

use cli::parser::{CliArgs, Parser};
use server::services::{connect::connect, reader::read_message};
use shared::types::filesystem::FileExtension;
use shared::types::fractal_descriptor::FractalType::Julia;
use shared::types::fractal_descriptor::{FractalDescriptor, JuliaDescriptor};
Expand All @@ -15,12 +17,9 @@ use shared::types::range::Range;
use shared::types::u8data::U8Data;
use shared::types::{complex::Complex, resolution::Resolution};
use shared::utils::filesystem::{get_dir_path_buf, get_extension_str, get_file_path};
use cli::parser::{CliArgs, Parser};
use server::services::{reader::read_message, connect::connect};


fn main() -> io::Result<()> {
let args : CliArgs = CliArgs::parse();
let args: CliArgs = CliArgs::parse();
let stream = connect(format!("{}:{}", args.hostname, args.port).as_str())?;
let message = read_message(stream);
println!("{}", message);
Expand Down
2 changes: 1 addition & 1 deletion client/src/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod networking;
pub mod image;
pub mod julia;
pub mod networking;
1 change: 1 addition & 0 deletions client/src/networking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion server/src/services/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod connect;
pub mod reader;
pub mod write;
pub mod reader;
6 changes: 3 additions & 3 deletions server/src/services/reader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::TcpStream, io::Read};
use std::{io::Read, net::TcpStream};

/// Read a message from a TCP stream.
///
Expand All @@ -20,11 +20,11 @@ use std::{net::TcpStream, io::Read};
/// ```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);
/// ```
Expand Down
8 changes: 4 additions & 4 deletions server/src/services/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ use std::net::TcpStream;
/// # Return
///
/// * `Result<TcpStream, std::io::Error>` - TcpStream
///
///
/// # Example
///
///
/// ```no_run
/// use std::net::TcpStream;
/// use server::services::write::write;
///
///
/// let stream = TcpStream::connect("localhost:8787").unwrap();
/// let stream = write(stream, "Hello world!").unwrap();
/// ```
///
///
pub fn write(mut stream: TcpStream, message: &str) -> Result<TcpStream> {
stream.write(format!("${}", message).as_bytes())?;

Expand Down

0 comments on commit 19d1100

Please sign in to comment.