diff --git a/src/cmd/profile/mod.rs b/src/cmd/profile/mod.rs index cc4e396..f27980b 100644 --- a/src/cmd/profile/mod.rs +++ b/src/cmd/profile/mod.rs @@ -1,11 +1,15 @@ mod list; +mod show; use anyhow::Result; use clap::{Parser, Subcommand}; #[derive(Debug, Subcommand)] pub enum Action { + /// Lists all configured profiles. List(list::Cmd), + /// Shows a profile in TOML format. + Show(show::Cmd), } #[derive(Debug, Parser)] @@ -19,6 +23,7 @@ impl Cmd { use Action::*; match self.action { List(cmd) => cmd.run(), + Show(cmd) => cmd.run(), } } } diff --git a/src/cmd/profile/show.rs b/src/cmd/profile/show.rs new file mode 100644 index 0000000..6547a69 --- /dev/null +++ b/src/cmd/profile/show.rs @@ -0,0 +1,24 @@ +use anyhow::{anyhow, Result}; +use clap::Parser; + +use crate::config::Config; + +#[derive(Debug, Parser)] +pub struct Cmd { + // Name of the profile to show. + name: String, +} + +impl Cmd { + pub fn run(self) -> Result<()> { + let config = Config::load()?; + let profile = config + .profiles + .get(&self.name) + .ok_or_else(|| anyhow!("Unknown profile: {}", &self.name))?; + + print!("{}", toml::to_string(profile)?); + + Ok(()) + } +} diff --git a/src/profile.rs b/src/profile.rs index 2021015..1fa921d 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -4,9 +4,9 @@ use std::ops::Deref; use crate::rule::ProfileRef; use anyhow::Result; use git2::Config; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Serialize)] pub struct User { #[serde(default)] pub name: Option, @@ -14,7 +14,7 @@ pub struct User { pub email: Option, } -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Serialize)] pub struct Profile { #[serde(default)] pub user: Option,