Skip to content

Commit 2394306

Browse files
committed
editoast: add cli arg to control colored output
1 parent 8c80d80 commit 2394306

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

editoast/Cargo.lock

+24-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editoast/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ osm4routing = "0.5.8"
6464
osmpbfreader = "0.16.0"
6565
itertools = "0.11"
6666
utoipa = { version = "3.5", features = ["actix_extras"] }
67+
atty = "0.2.14"
6768

6869
[dev-dependencies]
6970
async-std = { version = "1.12", features = ["attributes", "tokio1"] }

editoast/src/client/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod postgres_config;
22
mod redis_config;
33

4-
use clap::{Args, Parser, Subcommand};
4+
use clap::{Args, Parser, Subcommand, ValueEnum};
55
use derivative::Derivative;
66
pub use postgres_config::PostgresConfig;
77
pub use redis_config::RedisConfig;
@@ -14,10 +14,21 @@ pub struct Client {
1414
pub postgres_config: PostgresConfig,
1515
#[command(flatten)]
1616
pub redis_config: RedisConfig,
17+
#[arg(long, env, value_enum, default_value_t = Color::Auto)]
18+
pub color: Color,
1719
#[command(subcommand)]
1820
pub command: Commands,
1921
}
2022

23+
#[derive(ValueEnum, Debug, Derivative, Clone)]
24+
#[derivative(Default)]
25+
pub enum Color {
26+
Never,
27+
Always,
28+
#[derivative(Default)]
29+
Auto,
30+
}
31+
2132
#[derive(Subcommand, Debug)]
2233
pub enum Commands {
2334
Runserver(RunserverArgs),

editoast/src/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use actix_web::{App, HttpServer};
2929
use chashmap::CHashMap;
3030
use clap::Parser;
3131
use client::{
32-
ClearArgs, Client, Commands, GenerateArgs, ImportProfileSetArgs, ImportRailjsonArgs,
32+
ClearArgs, Client, Color, Commands, GenerateArgs, ImportProfileSetArgs, ImportRailjsonArgs,
3333
PostgresConfig, RedisConfig, RunserverArgs,
3434
};
3535
use colored::*;
@@ -71,6 +71,12 @@ async fn run() -> Result<(), Box<dyn Error + Send + Sync>> {
7171
let pg_config = client.postgres_config;
7272
let redis_config = client.redis_config;
7373

74+
match client.color {
75+
Color::Never => colored::control::set_override(false),
76+
Color::Always => colored::control::set_override(true),
77+
Color::Auto => colored::control::set_override(atty::is(atty::Stream::Stderr)),
78+
}
79+
7480
match client.command {
7581
Commands::Runserver(args) => runserver(args, pg_config, redis_config).await,
7682
Commands::Generate(args) => generate(args, pg_config, redis_config).await,

0 commit comments

Comments
 (0)