Skip to content

Commit

Permalink
feat: Support showing a profile
Browse files Browse the repository at this point in the history
  • Loading branch information
siketyan committed Nov 5, 2022
1 parent c264b59 commit ccdb3d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions 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)]
Expand All @@ -19,6 +23,7 @@ impl Cmd {
use Action::*;
match self.action {
List(cmd) => cmd.run(),
Show(cmd) => cmd.run(),
}
}
}
24 changes: 24 additions & 0 deletions 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(())
}
}
6 changes: 3 additions & 3 deletions src/profile.rs
Expand Up @@ -4,17 +4,17 @@ 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<String>,
#[serde(default)]
pub email: Option<String>,
}

#[derive(Debug, Default, Deserialize)]
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Profile {
#[serde(default)]
pub user: Option<User>,
Expand Down

0 comments on commit ccdb3d4

Please sign in to comment.