ascii_cli/
cli.rs

1use clap::{Parser, Subcommand};
2use std::io::BufRead;
3
4#[derive(Debug, Parser)]
5#[command(version, about)]
6pub struct Args {
7    #[command(subcommand)]
8    pub command: Option<SubCommands>,
9}
10
11#[derive(Subcommand, Debug)]
12pub enum SubCommands {
13    /// Shows the Ascii table
14    Table {
15        /// The numbers base, deafults to 16 (Hexadecimal) [max is 36]
16        #[arg(short, long, default_value_t = 16)]
17        base: u8,
18    },
19    ToChar {
20        /// The number(s) to be converted to a character
21        #[clap(num_args = 1.., value_delimiter = ' ')]
22        number: Option<Vec<String>>,
23        /// The numbers base, deafults to 16 (Hexadecimal) [max is 36]
24        #[arg(short, long, default_value_t = 16)]
25        base: u8,
26        /// If it should print special characters as their name, or make them act as usual
27        /// (Example: 7 is BEL if false, or it will make a bell sound if true)
28        #[arg(short, long)]
29        ignore_specials: bool,
30    },
31    ToNum {
32        /// The char(s) to be converted to a character
33        #[clap(num_args = 1.., value_delimiter = ' ')]
34        char: Option<Vec<String>>,
35        /// The numbers base, deafults to 16 (Hexadecimal) [max is 36]
36        #[arg(short, long, default_value_t = 16)]
37        base: u8,
38    },
39    WhatIs {
40        /// The number of the char you want to know more about, or the special characters name if
41        /// its a special character you want to know about (If so, use the -s flag)
42        character: Option<String>,
43        /// The numbers base, deafults to 16 (Hexadecimal) [max is 36]
44        #[arg(short, long, default_value_t = 16)]
45        base: u8,
46        /// Set this flag if the string is the name of a special character, like CR
47        #[arg(short, long)]
48        special: bool,
49    },
50}
51
52impl Default for SubCommands {
53    fn default() -> Self {
54        Self::Table { base: 16 }
55    }
56}
57
58pub fn get_std_in() -> String {
59    std::io::stdin()
60        .lock()
61        .lines()
62        .fold("".to_string(), |acc, line| {
63            acc + &line.unwrap_or_default() + "\n"
64        })
65}