Skip to content

Commit

Permalink
primitive implementation of clap complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
Localghost385 committed Jun 12, 2024
1 parent 2d8906c commit 86d40ec
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 18 deletions.
18 changes: 14 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion cli/lib.rs

This file was deleted.

38 changes: 26 additions & 12 deletions cli/main.rs
Original file line number Diff line number Diff line change
@@ -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;

// █▄█ ██▀ █ █▀▄ ██▀ █▀▄ █▀ █ █ █▄ █ ▄▀▀ ▀█▀ █ ▄▀▄ █▄ █ ▄▀▀
// █ █ █▄▄ █▄▄ █▀ █▄▄ █▀▄ █▀ ▀▄█ █ ▀█ ▀▄▄ █ █ ▀▄▀ █ ▀█ ▄██
Expand All @@ -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),
)
Expand Down Expand Up @@ -57,33 +59,45 @@ 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<G: Generator>(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();
if version {
println!("glyphrs v{}", env!("CARGO_PKG_VERSION"));
std::process::exit(0);
}

if let Some(generator) = matches.get_one::<Shell>("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::<String>("input").unwrap().to_string();
let font: String = matches.get_one::<String>("font").unwrap().to_string();
let prefix: String = matches.get_one::<String>("prefix").unwrap().to_string();




// ▄▀ ██▀ █▄ █ ██▀ █▀▄ ▄▀▄ ▀█▀ ██▀ █▄ ▄█ ██▀ ▄▀▀ ▄▀▀ ▄▀▄ ▄▀ ██▀
// ▀▄█ █▄▄ █ ▀█ █▄▄ █▀▄ █▀█ █ █▄▄ █ ▀ █ █▄▄ ▄██ ▄██ █▀█ ▀▄█ █▄▄
let output = convert_input(input, font, prefix);
Expand Down
20 changes: 20 additions & 0 deletions page/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions vscode_extension/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 16 additions & 1 deletion vscode_extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 86d40ec

Please sign in to comment.