mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 05:06:29 +00:00
Add configurable color options
This commit is contained in:
@@ -16,6 +16,7 @@ use std::{
|
||||
};
|
||||
|
||||
use structopt::StructOpt;
|
||||
use thiserror::Error;
|
||||
|
||||
pub use self::build::*;
|
||||
pub use self::doc::*;
|
||||
@@ -27,16 +28,73 @@ pub use self::upload::*;
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(name = "Rojo", about, author)]
|
||||
pub struct Options {
|
||||
/// Sets verbosity level. Can be specified multiple times.
|
||||
#[structopt(long = "verbose", short, global(true), parse(from_occurrences))]
|
||||
pub verbosity: u8,
|
||||
#[structopt(flatten)]
|
||||
pub global: GlobalOptions,
|
||||
|
||||
/// Subcommand to run in this invocation.
|
||||
#[structopt(subcommand)]
|
||||
pub subcommand: Subcommand,
|
||||
}
|
||||
|
||||
/// All of Rojo's subcommands.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct GlobalOptions {
|
||||
/// Sets verbosity level. Can be specified multiple times.
|
||||
#[structopt(long("verbose"), short, global(true), parse(from_occurrences))]
|
||||
pub verbosity: u8,
|
||||
|
||||
/// Set color behavior. Valid values are auto, always, and never.
|
||||
#[structopt(long("color"), global(true), default_value("auto"))]
|
||||
pub color: ColorChoice,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ColorChoice {
|
||||
Auto,
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
|
||||
impl FromStr for ColorChoice {
|
||||
type Err = ColorChoiceParseError;
|
||||
|
||||
fn from_str(source: &str) -> Result<Self, Self::Err> {
|
||||
match source {
|
||||
"auto" => Ok(ColorChoice::Auto),
|
||||
"always" => Ok(ColorChoice::Always),
|
||||
"never" => Ok(ColorChoice::Never),
|
||||
_ => Err(ColorChoiceParseError {
|
||||
attempted: source.to_owned(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ColorChoice> for termcolor::ColorChoice {
|
||||
fn from(value: ColorChoice) -> Self {
|
||||
match value {
|
||||
ColorChoice::Auto => termcolor::ColorChoice::Auto,
|
||||
ColorChoice::Always => termcolor::ColorChoice::Always,
|
||||
ColorChoice::Never => termcolor::ColorChoice::Never,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ColorChoice> for env_logger::WriteStyle {
|
||||
fn from(value: ColorChoice) -> Self {
|
||||
match value {
|
||||
ColorChoice::Auto => env_logger::WriteStyle::Auto,
|
||||
ColorChoice::Always => env_logger::WriteStyle::Always,
|
||||
ColorChoice::Never => env_logger::WriteStyle::Never,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[error("Invalid color choice '{attempted}'. Valid values are: auto, always, never")]
|
||||
pub struct ColorChoiceParseError {
|
||||
attempted: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub enum Subcommand {
|
||||
/// Creates a new Rojo project.
|
||||
|
||||
Reference in New Issue
Block a user