Skip to content

Commit e478899

Browse files
0rpheeryanccn
andauthored
feat: add remove command (#89)
Co-authored-by: Ryan Cao <[email protected]>
1 parent 73a23ee commit e478899

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
path: artifacts
2222

2323
- name: Upload to release
24-
uses: softprops/action-gh-release@v1
24+
uses: softprops/action-gh-release@v2
2525
with:
2626
files: artifacts/**/*
2727

src/cmd/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod config;
1010
mod list;
1111
mod preset;
1212
mod profile;
13+
mod remove;
1314
mod switch;
1415

1516
#[derive(Parser)]
@@ -35,6 +36,8 @@ pub enum Commands {
3536
List(list::ListCommand),
3637
/// Add a new userchrome
3738
Add(add::AddCommand),
39+
/// Remove a userchrome
40+
Remove(remove::RemoveCommand),
3841
/// Switch to a userchrome
3942
Switch(switch::SwitchCommand),
4043
/// Import a preset as a userchrome or list presets

src/cmd/remove.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use clap::Parser;
2+
use color_eyre::{
3+
eyre::{eyre, Result},
4+
owo_colors::OwoColorize as _,
5+
};
6+
7+
use crate::config;
8+
9+
#[derive(Parser)]
10+
pub struct RemoveCommand {
11+
/// Name of the userchrome
12+
name: String,
13+
}
14+
15+
impl super::Command for RemoveCommand {
16+
async fn action(&self, global_options: &super::Cli) -> Result<()> {
17+
let mut config = config::get_config(&global_options.config).await?;
18+
19+
let res = config
20+
.userchromes
21+
.iter()
22+
.enumerate()
23+
.find(|(_, uchrome)| uchrome.name.eq(&self.name));
24+
25+
match res {
26+
Some((i, uchrome)) => {
27+
println!("Removing {}!", uchrome.name.cyan());
28+
config::print_userchrome(uchrome, true);
29+
30+
config.userchromes.remove(i);
31+
config::set_config(&global_options.config, &config).await?;
32+
Ok(())
33+
}
34+
None => Err(eyre!(
35+
"no userchrome with name {} found to remove!",
36+
self.name
37+
)),
38+
}
39+
}
40+
}

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use color_eyre::eyre::{eyre, Result};
22
use std::path::{Path, PathBuf};
33
use tokio::fs;
44

5-
use owo_colors::OwoColorize;
5+
use owo_colors::OwoColorize as _;
66
use serde::{Deserialize, Serialize};
77

88
#[derive(Deserialize, Serialize, Debug)]

src/switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
use tokio::{fs, process::Command};
99

1010
use nanoid::nanoid;
11-
use owo_colors::OwoColorize;
11+
use owo_colors::OwoColorize as _;
1212
use regex::Regex;
1313

1414
use crate::{

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tokio::fs;
99

1010
use color_eyre::eyre::{eyre, Result};
1111
use nanoid::nanoid;
12-
use owo_colors::OwoColorize;
12+
use owo_colors::OwoColorize as _;
1313
use sysinfo::{ProcessRefreshKind, RefreshKind, System};
1414
use zip::ZipArchive;
1515

0 commit comments

Comments
 (0)