Skip to content

Commit 7ede210

Browse files
committed
fix(profile): check existence and type
1 parent 8739247 commit 7ede210

File tree

10 files changed

+54
-69
lines changed

10 files changed

+54
-69
lines changed

Cargo.lock

Lines changed: 30 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ publish = false
1313
[dependencies]
1414
async-recursion = "1.1.1"
1515
bzip2 = "0.4.4"
16-
clap = { version = "4.5.19", features = ["derive"] }
17-
clap_complete = "4.5.32"
16+
clap = { version = "4.5.20", features = ["derive"] }
17+
clap_complete = "4.5.33"
1818
color-eyre = "0.6.3"
1919
dirs = "5.0.1"
2020
enum_dispatch = "0.3.13"

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl super::Command for ConfigCommand {
4949
let uc = config
5050
.userchromes
5151
.iter()
52-
.find(|d| d.name.eq(name))
52+
.find(|d| &d.name == name)
5353
.ok_or_else(|| eyre!("no userchrome with name {} exists", name))?;
5454

5555
for c in &uc.configs {
@@ -69,7 +69,7 @@ impl super::Command for ConfigCommand {
6969
let chrome = config
7070
.userchromes
7171
.iter_mut()
72-
.find(|d| d.name.eq(name))
72+
.find(|d| &d.name == name)
7373
.ok_or_else(|| eyre!("no userchrome with name {} exists", name))?;
7474

7575
let existing = chrome.configs.iter_mut().find(|c| c.key == *key);
@@ -95,7 +95,7 @@ impl super::Command for ConfigCommand {
9595
let chrome = config
9696
.userchromes
9797
.iter_mut()
98-
.find(|d| d.name.eq(name))
98+
.find(|d| &d.name == name)
9999
.ok_or_else(|| eyre!("no userchrome with name {} exists", name))?;
100100

101101
let existing = chrome.configs.iter_mut().position(|c| c.key == *key);

src/cmd/profile.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::path::PathBuf;
66

77
use clap::{Parser, ValueHint};
8-
use eyre::Result;
8+
use eyre::{bail, Result};
99
use owo_colors::OwoColorize as _;
1010

1111
use crate::config;
@@ -20,6 +20,10 @@ pub struct ProfileCommand {
2020
impl super::Command for ProfileCommand {
2121
async fn action(&self, global_options: &super::Cli) -> Result<()> {
2222
if let Some(path) = &self.path {
23+
if !path.is_dir() {
24+
bail!("profile does not exist");
25+
}
26+
2327
let mut config = config::get_config(&global_options.config).await?;
2428
config.profile = Some(path.clone());
2529
config::set_config(&global_options.config, &config).await?;

src/cmd/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl super::Command for RemoveCommand {
2424
.userchromes
2525
.iter()
2626
.enumerate()
27-
.find(|(_, uchrome)| uchrome.name.eq(&self.name));
27+
.find(|(_, uchrome)| uchrome.name == self.name);
2828

2929
match res {
3030
Some((i, uchrome)) => {

src/cmd/switch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ impl super::Command for SwitchCommand {
1717
async fn action(&self, global_options: &super::Cli) -> Result<()> {
1818
let config = config::get_config(&global_options.config).await?;
1919

20-
utils::check_firefox()?;
20+
utils::check_firefox();
2121

2222
if let Some(profile) = &config.profile {
2323
if self.name == "out" {
2424
switch::switch(None, profile).await?;
25-
} else if let Some(u) = config.userchromes.iter().find(|c| c.name.eq(&self.name)) {
25+
} else if let Some(u) = config.userchromes.iter().find(|c| c.name == self.name) {
2626
switch::switch(Some(u), profile).await?;
2727
} else {
2828
bail!("no userchrome with name {} found!", self.name);

src/cmd/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl super::Command for UpdateCommand {
1616
async fn action(&self, global_options: &super::Cli) -> Result<()> {
1717
let config = config::get_config(&global_options.config).await?;
1818

19-
utils::check_firefox()?;
19+
utils::check_firefox();
2020

2121
if let Some(profile) = &config.profile {
2222
let current = fs::read_to_string(profile.join("chrome").join(".nyoom-chrome-name"))

src/switch.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
use eyre::{bail, Result};
66
use temp_dir::TempDir;
77

8-
use std::{
9-
env,
10-
path::{Path, PathBuf},
11-
process::Stdio,
12-
sync::LazyLock,
13-
};
8+
use std::{env, path::Path, process::Stdio, sync::LazyLock};
149
use tokio::{fs, process::Command};
1510

1611
use owo_colors::OwoColorize as _;
@@ -78,8 +73,8 @@ async fn patch_user_file(f: &Path, userchrome: Option<&Userchrome>) -> Result<()
7873
}
7974

8075
let mut ret_lines: Vec<String> = Vec::new();
81-
let start_idx = lines.iter().position(|k| k.eq(&START_LINE));
82-
let end_idx = lines.iter().position(|k| k.eq(&END_LINE));
76+
let start_idx = lines.iter().position(|k| k == START_LINE);
77+
let end_idx = lines.iter().position(|k| k == END_LINE);
8378

8479
let mut ret_set = false;
8580

@@ -173,12 +168,12 @@ async fn handle_source(source: &str, target_dir: &Path) -> Result<()> {
173168

174169
utils::download_archive(&url, target_dir).await?;
175170
} else if let Some(path) = source.strip_prefix("path:") {
176-
let source = PathBuf::from(path);
171+
let source = Path::new(path);
177172
if !source.is_dir() {
178173
bail!("provided path {path:?} is not a directory");
179174
}
180175

181-
utils::copy_dir_all(&source, target_dir).await?;
176+
utils::copy_dir_all(source, target_dir).await?;
182177
} else if let Some(url) = source.strip_prefix("url:") {
183178
utils::download_archive(url, target_dir).await?;
184179
} else if source.starts_with("https://") || source.starts_with("http://") {

src/utils/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ pub async fn copy_dir_all(src: &Path, dst: &Path) -> Result<()> {
3131
Ok(())
3232
}
3333

34-
pub fn check_firefox() -> Result<()> {
34+
pub fn check_firefox() {
3535
let system =
3636
System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()));
37-
let is_running = system
38-
.processes_by_name(&"firefox".parse::<OsString>()?)
39-
.count()
40-
!= 0;
37+
let is_running = system.processes_by_name(&OsString::from("firefox")).count() != 0;
4138

4239
if is_running {
4340
println!("{}", "Firefox is running, refusing to continue!".yellow());
4441
exit(1);
4542
}
46-
47-
Ok(())
4843
}

0 commit comments

Comments
 (0)