From 8eaee575241b6c71a8b95da88539fc65a2e9101d Mon Sep 17 00:00:00 2001 From: David Barnett Date: Thu, 29 Feb 2024 21:00:32 -0600 Subject: [PATCH 1/3] feat(cli): support trivial cli args like --version Fixes #42. --- .changeset/warm-ladybugs-exist.md | 5 ++ apps/core/src-tauri/Cargo.lock | 109 +++++++++++++++++++++++++++++- apps/core/src-tauri/Cargo.toml | 1 + apps/core/src-tauri/src/main.rs | 9 +++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 .changeset/warm-ladybugs-exist.md diff --git a/.changeset/warm-ladybugs-exist.md b/.changeset/warm-ladybugs-exist.md new file mode 100644 index 00000000..083c311f --- /dev/null +++ b/.changeset/warm-ladybugs-exist.md @@ -0,0 +1,5 @@ +--- +"@tablex/core": patch +--- + +Support trivial cli args like --version diff --git a/apps/core/src-tauri/Cargo.lock b/apps/core/src-tauri/Cargo.lock index b4ed57d2..f8afc433 100644 --- a/apps/core/src-tauri/Cargo.lock +++ b/apps/core/src-tauri/Cargo.lock @@ -75,6 +75,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.79" @@ -365,6 +413,46 @@ dependencies = [ "windows-targets 0.52.0", ] +[[package]] +name = "clap" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.0", +] + +[[package]] +name = "clap_derive" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + [[package]] name = "clipboard-win" version = "4.5.0" @@ -412,6 +500,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "combine" version = "4.6.6" @@ -617,7 +711,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 2.0.48", ] @@ -3351,6 +3445,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "subtle" version = "2.5.0" @@ -3422,6 +3522,7 @@ dependencies = [ name = "table_x" version = "0.1.0" dependencies = [ + "clap", "regex", "serde", "serde_json", @@ -4066,6 +4167,12 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.7.0" diff --git a/apps/core/src-tauri/Cargo.toml b/apps/core/src-tauri/Cargo.toml index 8bacc006..c152dda3 100644 --- a/apps/core/src-tauri/Cargo.toml +++ b/apps/core/src-tauri/Cargo.toml @@ -22,6 +22,7 @@ strip = true tauri-build = { version = "1.5.0", features = [] } [dependencies] +clap = { version = "4.5.1", features = ["derive"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.5.2", features = [ "shell-open", "os-all", "clipboard-write-text", "global-shortcut-all", "dialog-open", "test", "process-command-api"] } diff --git a/apps/core/src-tauri/src/main.rs b/apps/core/src-tauri/src/main.rs index dd7a55bd..fb7a223b 100644 --- a/apps/core/src-tauri/src/main.rs +++ b/apps/core/src-tauri/src/main.rs @@ -7,6 +7,7 @@ mod row; mod table; mod utils; +use clap::Parser; use connection::{ connections_exist, create_connection_record, delete_connection_record, establish_connection, get_connection_details, get_connections, test_connection, @@ -21,6 +22,10 @@ use tauri::{Manager, WindowEvent}; use tokio::sync::Mutex; use utils::Drivers; +#[derive(Parser, Debug)] +#[command(version, about)] +struct Args {} + #[derive(Default)] pub struct DbInstance { sqlite_pool: Mutex>, @@ -62,6 +67,10 @@ impl DbInstance { } fn main() { + // Process basic cli args (like --help and --version). + // TODO: #46 - Support arguments such as DB connection. + Args::parse(); + tauri::Builder::default() .manage(DbInstance { sqlite_pool: Default::default(), From 10fd25ac9b12276cf7d5168fb1cc5ec0135943f9 Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Mon, 18 Mar 2024 15:09:25 +0200 Subject: [PATCH 2/3] =?UTF-8?q?fix(windows):=20attach,=20process=20then=20?= =?UTF-8?q?free=20the=20console=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierignore | 3 +- apps/core/src-tauri/Cargo.lock | 86 ++++++++++++++++++++++----------- apps/core/src-tauri/Cargo.toml | 3 ++ apps/core/src-tauri/src/cli.rs | 36 ++++++++++++++ apps/core/src-tauri/src/main.rs | 10 +--- 5 files changed, 101 insertions(+), 37 deletions(-) create mode 100644 apps/core/src-tauri/src/cli.rs diff --git a/.prettierignore b/.prettierignore index dadcd21b..de487fb5 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,4 +8,5 @@ pnpm-lock.yaml apps/core/src/components apps/web/src/components apps/web-astro/src/components -.all-contributorsrc \ No newline at end of file +.all-contributorsrc +**/routeTree.gen.ts \ No newline at end of file diff --git a/apps/core/src-tauri/Cargo.lock b/apps/core/src-tauri/Cargo.lock index f8afc433..92cfd596 100644 --- a/apps/core/src-tauri/Cargo.lock +++ b/apps/core/src-tauri/Cargo.lock @@ -410,7 +410,7 @@ dependencies = [ "iana-time-zone", "num-traits", "serde", - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -1535,7 +1535,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -3532,6 +3532,7 @@ dependencies = [ "time", "tokio", "uuid", + "windows 0.54.0", ] [[package]] @@ -4522,6 +4523,16 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +dependencies = [ + "windows-core 0.54.0", + "windows-targets 0.52.4", +] + [[package]] name = "windows-bindgen" version = "0.39.0" @@ -4538,7 +4549,17 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-core" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +dependencies = [ + "windows-result", + "windows-targets 0.52.4", ] [[package]] @@ -4557,6 +4578,15 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ee5e275231f07c6e240d14f34e1b635bf1faa1c76c57cfd59a5cdb9848e4278" +[[package]] +name = "windows-result" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd19df78e5168dfb0aedc343d1d1b8d422ab2db6756d2dc3fef75035402a3f64" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-sys" version = "0.42.0" @@ -4596,7 +4626,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -4631,17 +4661,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -4656,7 +4686,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75aa004c988e080ad34aff5739c39d0312f4684699d6d71fc8a198d057b8b9b4" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -4673,9 +4703,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -4703,9 +4733,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -4733,9 +4763,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -4763,9 +4793,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -4793,9 +4823,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -4811,9 +4841,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -4841,9 +4871,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winnow" diff --git a/apps/core/src-tauri/Cargo.toml b/apps/core/src-tauri/Cargo.toml index c152dda3..a86002f0 100644 --- a/apps/core/src-tauri/Cargo.toml +++ b/apps/core/src-tauri/Cargo.toml @@ -37,3 +37,6 @@ regex = "1.10.3" # If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes. # DO NOT REMOVE!! custom-protocol = [ "tauri/custom-protocol" ] + +[target."cfg(windows)".dependencies] +windows = { version = "0.54.0", features = ["Win32_System_Console", "Win32_Foundation"] } diff --git a/apps/core/src-tauri/src/cli.rs b/apps/core/src-tauri/src/cli.rs new file mode 100644 index 00000000..8eee371a --- /dev/null +++ b/apps/core/src-tauri/src/cli.rs @@ -0,0 +1,36 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +#[command(version, about)] +pub(crate) struct Args {} + +/// Only on windows. +/// +/// Attaches the console so the user can see output in the terminal. +fn attach_console() { + use windows::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS}; + let _ = unsafe { AttachConsole(ATTACH_PARENT_PROCESS) }; +} + +/// Only on windows. +/// +/// Frees the console so the user won't see weird println's +/// after he is done using the cli. +fn free_console() { + use windows::Win32::System::Console::FreeConsole; + let _ = unsafe { FreeConsole() }; +} + +// TODO: #46 - Support arguments such as DB connection. +/// Process basic cli args (like --help and --version). +pub(crate) fn parse_cli_args() -> Args { + #[cfg(windows)] + attach_console(); + + let args = Args::parse(); + + #[cfg(windows)] + free_console(); + + args +} diff --git a/apps/core/src-tauri/src/main.rs b/apps/core/src-tauri/src/main.rs index fb7a223b..4ae46aa4 100644 --- a/apps/core/src-tauri/src/main.rs +++ b/apps/core/src-tauri/src/main.rs @@ -1,13 +1,13 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +mod cli; mod connection; mod drivers; mod row; mod table; mod utils; -use clap::Parser; use connection::{ connections_exist, create_connection_record, delete_connection_record, establish_connection, get_connection_details, get_connections, test_connection, @@ -22,10 +22,6 @@ use tauri::{Manager, WindowEvent}; use tokio::sync::Mutex; use utils::Drivers; -#[derive(Parser, Debug)] -#[command(version, about)] -struct Args {} - #[derive(Default)] pub struct DbInstance { sqlite_pool: Mutex>, @@ -67,9 +63,7 @@ impl DbInstance { } fn main() { - // Process basic cli args (like --help and --version). - // TODO: #46 - Support arguments such as DB connection. - Args::parse(); + cli::parse_cli_args(); tauri::Builder::default() .manage(DbInstance { From 8d4a68221b737b98a0d6b13aa7fe0c6922b59657 Mon Sep 17 00:00:00 2001 From: Kareem Ebrahim Date: Tue, 19 Mar 2024 14:25:28 +0200 Subject: [PATCH 3/3] =?UTF-8?q?fix(windows):=20guard=20attach=20&=20free?= =?UTF-8?q?=20fn=20definitions=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/core/src-tauri/src/cli.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/core/src-tauri/src/cli.rs b/apps/core/src-tauri/src/cli.rs index 8eee371a..3da86cc3 100644 --- a/apps/core/src-tauri/src/cli.rs +++ b/apps/core/src-tauri/src/cli.rs @@ -7,6 +7,7 @@ pub(crate) struct Args {} /// Only on windows. /// /// Attaches the console so the user can see output in the terminal. +#[cfg(windows)] fn attach_console() { use windows::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS}; let _ = unsafe { AttachConsole(ATTACH_PARENT_PROCESS) }; @@ -16,6 +17,7 @@ fn attach_console() { /// /// Frees the console so the user won't see weird println's /// after he is done using the cli. +#[cfg(windows)] fn free_console() { use windows::Win32::System::Console::FreeConsole; let _ = unsafe { FreeConsole() };