Skip to content

Commit

Permalink
feat(emoji): add global flag to disable emoji display
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 19, 2023
1 parent f162b0e commit bafbe80
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/commands/restore.rs
Expand Up @@ -30,6 +30,9 @@ pub struct RestoreCmd {
#[clap(from_global)]
cache: Option<PathBuf>,

#[clap(from_global)]
no_emoji: bool,

/// Prefer copying files over hard linking them.
///
/// On filesystems that don't support copy-on-write/reflinks (usually NTFS
Expand Down Expand Up @@ -62,7 +65,7 @@ pub struct RestoreCmd {
impl OroCommand for RestoreCmd {
async fn execute(self) -> Result<()> {
let total_time = std::time::Instant::now();
let emoji = Emoji::new();
let emoji = Emoji::new(!self.no_emoji);
let root = self
.root
.as_deref()
Expand Down Expand Up @@ -265,8 +268,8 @@ fn hackerish_encouragement() -> &'static str {
struct Emoji(bool);

impl Emoji {
fn new() -> Self {
Self(supports_unicode::on(supports_unicode::Stream::Stderr))
fn new(use_emoji: bool) -> Self {
Self(use_emoji)
}

const PACKAGE: &'static str = "📦 ";
Expand All @@ -276,7 +279,11 @@ impl Emoji {
const TADA: &'static str = "🎉 ";

fn package(&self) -> &'static str {
Self::PACKAGE
if self.0 {
Self::PACKAGE
} else {
""
}
}

fn magnifying_glass(&self) -> &'static str {
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Expand Up @@ -105,6 +105,10 @@ pub struct Orogene {
#[arg(help_heading = "Global Options", global = true, long)]
no_progress: bool,

/// Disables all emoji usage.
#[arg(help_heading = "Global Options", global = true, long)]
no_emoji: bool,

#[command(subcommand)]
subcommand: OroCmd,
}
Expand Down Expand Up @@ -204,6 +208,10 @@ impl Orogene {
let mut cfg_builder = OroConfigOptions::new()
.set_default("registry", "https://registry.npmjs.org")?
.set_default("loglevel", "warn")?
.set_default(
"no_emoji",
&format!("{}", !supports_unicode::on(supports_unicode::Stream::Stderr)),
)?
.set_default("root", &root.to_string_lossy())?;
if let Some(cache) = dirs.as_ref().map(|d| d.cache_dir().to_owned()) {
cfg_builder = cfg_builder.set_default("cache", &cache.to_string_lossy())?;
Expand Down
4 changes: 4 additions & 0 deletions tests/snapshots/help__ping.snap
Expand Up @@ -67,4 +67,8 @@ Format output as JSON
Disable progress bar display
#### `--no-emoji`
Disables all emoji usage
4 changes: 4 additions & 0 deletions tests/snapshots/help__restore.snap
Expand Up @@ -85,4 +85,8 @@ Format output as JSON
Disable progress bar display
#### `--no-emoji`
Disables all emoji usage
4 changes: 4 additions & 0 deletions tests/snapshots/help__view.snap
Expand Up @@ -73,4 +73,8 @@ Format output as JSON
Disable progress bar display
#### `--no-emoji`
Disables all emoji usage

0 comments on commit bafbe80

Please sign in to comment.