playit-gg 0.1.0

Unofficial Rust wrapper for https://playit.gg
Documentation
use owo_colors::OwoColorize;
use std::env::args;
use std::env::current_exe;
use std::fmt;
use std::process::exit;

const USAGE: &str = "-t thing:thins:dwas";
const OPTIONS: &[CLIOption] = &[
  CLIOption {
    short: Some("d"),
    long: "213",
    description: "W",
    default: Some("dw"),
    required: false,
  },
  CLIOption {
    short: None,
    long: "widajdkjsahksjdh",
    description: "Hiello",
    default: None,
    required: true,
  },
];

fn main() {
  exit(_main());
}

fn _main() -> i32 {
  println!("{:#?}", args());
  println!("{}", help("AAAAAAAAAAAAAA", MessageType::Error));
  0
}

/// Returns the help message with
fn help(message: &str, message_type: MessageType) -> String {
  format!(
    "{}: {}\n\n{}",
    match message_type {
      MessageType::Error => "ERROR".red(),
      MessageType::HelpFlag => ""
    },
    message,
    format!(
      "
USAGE: {} {}

OPTIONS: 
\t{}
    ",
      current_exe()
        .unwrap()
        .file_name()
        .unwrap()
        .to_string_lossy(),
      USAGE,
      {
        let mut options = String::new();
        for option in OPTIONS.iter() {
          options.push_str(&(option.to_string() + "\n\t"))
        }
        options
      }
    )
  )
}

enum MessageType {
  Error,
  HelpFlag,
}

#[derive(Clone, PartialEq, Debug)]
struct CLIOption {
  short: Option<&'static str>,
  long: &'static str,
  description: &'static str,
  default: Option<&'static str>,
  required: bool,
}

impl fmt::Display for CLIOption {
  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    write!(
      f,
      "{}--{}: {}. {}",
      if let Some(short) = self.short {
        format!("-{}, ", short)
      } else {
        String::new()
      },
      self.long,
      self.description,
      if self.required {
        format!("This option is {}.", "required".red())
      } else {
        String::new()
      }
    )
  }
}