Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into code-highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
STBoyden committed Mar 3, 2022
2 parents 1ff5bf4 + fce1a8e commit 0b6b14a
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 93 deletions.
65 changes: 27 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 27 additions & 38 deletions codectrl-gui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codectrl-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = "1.58.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "2.33"
clap = { version = "3.1", features = ["cargo"] }
codectrl_logger = { git = "https://github.com/authentura/codectrl-rust-logger", default-features = false, features = ["types-only"] }
eframe = "0.16"
egui = { version = "0.16", features = ["persistence"] }
Expand Down
48 changes: 39 additions & 9 deletions codectrl-gui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_closure, thread_spawn_unchecked, scoped_threads)]
#![feature(async_closure, thread_spawn_unchecked)]
#![warn(clippy::pedantic)]
#![allow(
clippy::blocks_in_if_conditions,
Expand All @@ -18,7 +18,7 @@ extern crate clap;

use app::App;
#[cfg(not(target_arch = "wasm32"))]
use clap::{crate_authors, crate_name, crate_version, App as ClapApp, Arg};
use clap::{crate_authors, crate_name, crate_version, Arg, Command};
#[cfg(not(target_arch = "wasm32"))]
use codectrl_log_server::Server;
#[cfg(target_arch = "wasm32")]
Expand All @@ -39,25 +39,40 @@ pub fn run() -> Result<(), JsValue> {
pub async fn run() {
let command_line = env::vars().collect::<HashMap<String, String>>();

let matches = ClapApp::new(crate_name!())
let matches = Command::new(crate_name!())
.version(crate_version!())
.author(crate_authors!(", "))
.arg(
Arg::with_name("port")
Arg::new("port")
.takes_value(true)
.short("p")
.short('p')
.long("port")
.help(
"Specifies the port for the server to run on, can also be specified \
by the PORT environment variable",
),
)
.arg(
Arg::with_name("PROJECT")
Arg::new("host")
.takes_value(true)
.short('H')
.long("host")
.help(
"Specifies the IP address for the server to run on. Can also be \
specified with the HOST environment variable. Defaults to 0.0.0.0.",
),
)
.arg(
Arg::new("PROJECT")
.takes_value(true)
.index(1)
.help("The project file to load (optional)."),
)
.arg(
Arg::new("server_only")
.long("server-only")
.help("Only runs the back-end server, not the GUI."),
)
.get_matches();

let has_port = matches.is_present("port");
Expand All @@ -70,6 +85,16 @@ pub async fn run() {
"3001"
};

let has_host = matches.is_present("host");

let host = if has_host {
matches.value_of("host").unwrap()
} else if command_line.contains_key("HOST") {
command_line.get("HOST").unwrap()
} else {
"0.0.0.0"
};

let has_project = matches.is_present("PROJECT");

let project_file = if has_project {
Expand All @@ -78,12 +103,17 @@ pub async fn run() {
None
};

let socket_address = format!("127.0.0.1:{}", port);
let socket_address = format!("{host}:{port}");

let (mut server, receiver) = Server::new(host, port);

let (mut server, receiver) = Server::new(port);
if matches.is_present("server_only") {
server.run_server_current_runtime().await.unwrap();
return;
}

thread::spawn(move || {
server.run_server().unwrap();
server.run_server_new_runtime().unwrap();
});

let mut app = App::new(receiver, socket_address);
Expand Down
Loading

0 comments on commit 0b6b14a

Please sign in to comment.