Skip to content

Commit

Permalink
Slight improvement in code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
obvMellow committed Sep 2, 2024
1 parent 8939734 commit addfbbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub fn config(global: bool, key: String, val: String, dir: Option<PathBuf>) -> R
fs::create_dir_all(&path).context("Failed to create config directory")?;
path.push("distore.ini");

ConfigValue::write_to_path(&path.as_path(), &conf, scope)
ConfigValue::write_to_path(path.as_path(), &conf, scope)
.context("Failed to write to the config file")?;
println!("Set \"{}\" to \"{}\"", conf.to_string(), conf.inner());
println!("Set \"{}\"", conf);
Ok(())
}

Expand All @@ -50,8 +50,8 @@ pub fn get_config(global: bool, dir: Option<PathBuf>) -> Result<()> {
false => crate::config::ConfigValue::get_current_config(&path)?,
};

println!("Token: {}", token);
println!("Channel: {}", channel);
println!("{}", token);
println!("{}", channel);
Ok(())
}

Expand Down Expand Up @@ -293,7 +293,7 @@ pub async fn download(
);
let name = content
.split("\n")
.nth(0)
.next()
.unwrap()
.split("=")
.nth(1)
Expand Down Expand Up @@ -388,7 +388,7 @@ pub async fn list(token: Option<String>, channel: Option<u64>, dir: Option<PathB
);
let name = content
.split("\n")
.nth(0)
.next()
.unwrap()
.split("=")
.nth(1)
Expand Down
10 changes: 3 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Result<T> = std::result::Result<T, ConfigError>;

impl Display for ConfigValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self._pairs().1)
write!(f, "{}: {}", self._pairs().0, self.inner())
}
}

Expand All @@ -57,18 +57,14 @@ impl ConfigValue {
}
}

pub fn to_string(&self) -> String {
self._pairs().0.into()
}

pub fn inner(&self) -> &str {
self._pairs().1
}

fn _pairs(&self) -> (&str, &str) {
match self {
Self::Token(s) => ("token", s),
Self::Channel(s) => ("channel", s),
Self::Token(s) => ("Token", s),
Self::Channel(s) => ("Channel", s),
}
}

Expand Down

0 comments on commit addfbbb

Please sign in to comment.