diff --git a/Cargo.lock b/Cargo.lock index a139b57..ffd5f31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,18 +65,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.4" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" dependencies = [ "anstream", "anstyle", @@ -84,6 +84,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2020fa13af48afc65a9a87335bda648309ab3d154cd03c7ff95b378c7ed39c4" +dependencies = [ + "clap", +] + [[package]] name = "clap_lex" version = "0.7.0" @@ -107,6 +116,7 @@ name = "glyphrs" version = "0.2.2" dependencies = [ "clap", + "clap_complete", "serde", "toml", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index e1ef9ec..0a486d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] clap = "4.5.4" +clap_complete = "4.5.5" serde = { version = "1.0.203", features = ["derive"] } toml = "0.8.13" wasm-bindgen = "0.2.87" diff --git a/cli/lib.rs b/cli/lib.rs deleted file mode 100644 index 730a747..0000000 --- a/cli/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod clap; \ No newline at end of file diff --git a/cli/main.rs b/cli/main.rs index 0adc1a5..34a29db 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1,5 +1,7 @@ -use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint}; +use clap::{value_parser, Arg, ArgAction, ArgMatches, Command, ValueHint}; +use clap_complete::{generate, Generator, Shell}; use glyphrs_core::{fonts::font_handling::get_fonts, message_gen::convert_input}; +use std::io; // █▄█ ██▀ █ █▀▄ ██▀ █▀▄ █▀ █ █ █▄ █ ▄▀▀ ▀█▀ █ ▄▀▄ █▄ █ ▄▀▀ // █ █ █▄▄ █▄▄ █▀ █▄▄ █▀▄ █▀ ▀▄█ █ ▀█ ▀▄▄ █ █ ▀▄▀ █ ▀█ ▄██ @@ -26,7 +28,7 @@ pub fn clap_parse() -> Command { .about("A text art generator written in Rust") .arg( Arg::new("input") - .required_unless_present("version") + .required_unless_present_any(vec!["version", "generator"]) .help("the string to be converted") .value_hint(ValueHint::CommandString), ) @@ -57,14 +59,23 @@ pub fn clap_parse() -> Command { .short('v') .action(ArgAction::SetTrue) .help("Print version information"), + ) + .arg( + Arg::new("generator") + .long("generate") + .value_parser(value_parser!(Shell)), ); cmd } -// ▄▀▄ █▀▄ ▄▀ █▄█ ▄▀▄ █▄ █ █▀▄ █ █ █▄ █ ▄▀ -// █▀█ █▀▄ ▀▄█ █ █ █▀█ █ ▀█ █▄▀ █▄▄ █ █ ▀█ ▀▄█ -pub fn handle_args() -> ArgMatches { +fn print_completions(gen: G, cmd: &mut Command) { + generate(gen, cmd, "glyphrs".to_string(), &mut io::stdout()); +} + +fn main() { + // █▄█ ▄▀▄ █▄ █ █▀▄ █ ██▀ ▄▀▄ █▀▄ ▄▀ ▄▀▀ + // █ █ █▀█ █ ▀█ █▄▀ █▄▄ █▄▄ █▀█ █▀▄ ▀▄█ ▄██ let matches: ArgMatches = clap_parse().get_matches(); let version: bool = *matches.get_one("version").unwrap(); @@ -72,18 +83,21 @@ pub fn handle_args() -> ArgMatches { println!("glyphrs v{}", env!("CARGO_PKG_VERSION")); std::process::exit(0); } + + if let Some(generator) = matches.get_one::("generator") { + let mut cmd = clap_parse(); + eprintln!("Generating completion file for {generator}..."); + print_completions(*generator, &mut cmd); + std::process::exit(0); + } - matches -} - -fn main() { - // █▄█ ▄▀▄ █▄ █ █▀▄ █ ██▀ ▄▀▄ █▀▄ ▄▀ ▄▀▀ - // █ █ █▀█ █ ▀█ █▄▀ █▄▄ █▄▄ █▀█ █▀▄ ▀▄█ ▄██ - let matches = handle_args(); let input: String = matches.get_one::("input").unwrap().to_string(); let font: String = matches.get_one::("font").unwrap().to_string(); let prefix: String = matches.get_one::("prefix").unwrap().to_string(); + + + // ▄▀ ██▀ █▄ █ ██▀ █▀▄ ▄▀▄ ▀█▀ ██▀ █▄ ▄█ ██▀ ▄▀▀ ▄▀▀ ▄▀▄ ▄▀ ██▀ // ▀▄█ █▄▄ █ ▀█ █▄▄ █▀▄ █▀█ █ █▄▄ █ ▀ █ █▄▄ ▄██ ▄██ █▀█ ▀▄█ █▄▄ let output = convert_input(input, font, prefix); diff --git a/page/LICENSE b/page/LICENSE new file mode 100644 index 0000000..57fb98c --- /dev/null +++ b/page/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2024 Grace Murphy + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vscode_extension/LICENSE b/vscode_extension/LICENSE new file mode 100644 index 0000000..57fb98c --- /dev/null +++ b/vscode_extension/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2024 Grace Murphy + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vscode_extension/package.json b/vscode_extension/package.json index 5119710..4365eb0 100644 --- a/vscode_extension/package.json +++ b/vscode_extension/package.json @@ -25,7 +25,22 @@ "command": "glyphrs.insert", "title": "glyph.rs: Insert" } - ] + ], + "configuration": { + "title": "TypeScript", + "properties": { + "typescript.useCodeSnippetsOnMethodSuggest": { + "type": "boolean", + "default": false, + "description": "Complete functions with their parameter signature." + }, + "typescript.tsdk": { + "type": ["string", "null"], + "default": null, + "description": "Specifies the folder path containing the tsserver and lib*.d.ts files to use." + } + } + } }, "scripts": { "vscode:prepublish": "yarn run package",