Skip to content

Commit

Permalink
restructuring to prepare for combine with extension branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Localghost385 committed May 31, 2024
1 parent 48df01e commit 6c5ddd4
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 76 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ edition = "2021"
license = "MIT"
description = "A text art generator written in Rust"

[[bin]]
name = "glyphrs"
path = "./cli/main.rs"

[lib]
name = "glyphrs_core"
path = "./core/core.rs"
crate-type = ["cdylib", "rlib"]

[dependencies]
clap = "4.5.4"
serde = { version = "1.0.203", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs → cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use glyphrs::{clap, message_gen::*};
use glyphrs_core::{clap, message_gen::*};

fn main() {
// █▄█ ▄▀▄ █▄ █ █▀▄ █ ██▀ ▄▀▄ █▀▄ ▄▀ ▄▀▀
Expand Down
77 changes: 77 additions & 0 deletions core/clap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use crate::fonts::font_handling::get_fonts;
use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint};

// █▄█ ██▀ █ █▀▄ ██▀ █▀▄ █▀ █ █ █▄ █ ▄▀▀ ▀█▀ █ ▄▀▄ █▄ █ ▄▀▀
// █ █ █▄▄ █▄▄ █▀ █▄▄ █▀▄ █▀ ▀▄█ █ ▀█ ▀▄▄ █ █ ▀▄▀ █ ▀█ ▄██
fn string_to_str(input: Vec<String>) -> Vec<&'static str> {
let mut output: Vec<&'static str> = Vec::with_capacity(input.len());
for s in input {
output.push(Box::leak(s.into_boxed_str()));
}
output
}

// █▀▄ ▄▀▄ █▀▄ ▄▀▀ ██▀ █ █▄ █ █▀▄ █ █ ▀█▀
// █▀ █▀█ █▀▄ ▄██ █▄▄ █ █ ▀█ █▀ ▀▄█ █
pub fn clap_parse() -> Command {
let cmd = clap::Command::new("cargo")
.bin_name("glyphrs")
.before_help(
"".to_owned()
+ "-----------------------------\n"
+ "▄▀ █ ▀▄▀ █▀▄ █▄█ █▀▄ ▄▀▀\n"
+ "▀▄█ █▄▄ █ █▀ █ █ ▄ █▀▄ ▄██\n"
+ "-----------------------------",
)
.about("A text art generator written in Rust")
.arg(
Arg::new("input")
.required_unless_present("version")
.help("the string to be converted")
.value_hint(ValueHint::CommandString),
)
// ▄▀▄ █▀▄ ▄▀ ▄▀▀
// █▀█ █▀▄ ▀▄█ ▄██
.arg(
Arg::new("font")
.long("font")
.short('f')
.default_value("blocks_in_two_lines")
.value_parser(string_to_str(get_fonts()))
.help_heading("Output")
.help("set the font")
.value_hint(ValueHint::CommandString),
)
.arg(
Arg::new("prefix")
.long("prefix")
.short('p')
.default_value("")
.help_heading("Output")
.help("set the characters preceding each line, for example \"# \"")
.value_hint(ValueHint::CommandString),
)
.arg(
Arg::new("version")
.long("version")
.short('v')
.action(ArgAction::SetTrue)
.help("Print version information"),
);

cmd
}

// ▄▀▄ █▀▄ ▄▀ █▄█ ▄▀▄ █▄ █ █▀▄ █ █ █▄ █ ▄▀
// █▀█ █▀▄ ▀▄█ █ █ █▀█ █ ▀█ █▄▀ █▄▄ █ █ ▀█ ▀▄█
pub fn handle_args() -> ArgMatches {
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);
}

matches
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
75 changes: 0 additions & 75 deletions src/clap.rs

This file was deleted.

0 comments on commit 6c5ddd4

Please sign in to comment.