Skip to content

Commit

Permalink
Add command help
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-lloyd03 committed Jan 14, 2024
1 parent 4e32e0a commit 0139fc6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.75"
clap = { version = "4.4.11", features = ["derive"] }
clap = { version = "4.4.11", features = ["derive", "wrap_help"] }
sqlx = { version = "0.7.3", features = [
"sqlite",
"runtime-tokio",
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ If the `RUDRIC_SESSION` token is set in the environment:
- The expiration time and master key are decrypted from the session token using the session key
- If the token is not expired, the master key will be used to interact with secrets in the vault.

# Configuration

Rudric can be configured with a yaml file. By default, this file is stored in `XDG_CONFIG/rudric/config.yaml` (`$HOME/.config/rudric/config.yaml` on Linux and Mac). All config options are optional. An example config file might look like this:

```yaml
# Options are: bash, zsh, fish, nu
default_shell: fish

# Specify the default length of time that a session token is valid for
session_lifetime: 6h
```
# Crates
Encryption is all accomplished using the fantastic [Orion](https://github.com/orion-rs/orion) library.
Expand Down
50 changes: 49 additions & 1 deletion src/command/cli.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,99 @@
// #![deny(missing_docs)]
use clap::{Args, Parser, Subcommand};

use crate::types::shell_type::ShellType;

/// Store secrets in an encrypted state on disk
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
/// Specify a subcommand
#[command(subcommand)]
pub command: Command,

/// Specify an alternate config directory
#[arg(short, long)]
pub config_dir: Option<String>,
}

/// The subcommand to execute
#[derive(Subcommand)]
pub enum Command {
/// Set a master password and initialize the database
Init,

/// Create a new secret
Create {
/// The name of the secret (must be unique)
name: String,

/// Set the secret description
#[arg(short = 'd', long)]
description: Option<String>,
},

/// Fetch a secret value
Get {
/// The name of the secret
name: String,

/// Output the secret in json format
#[arg(long)]
json: bool,
},

/// Edit an existing secret. Will open the secret value in $EDITOR or $VISUAL
Edit {
/// The name of the secret
name: String,

/// Edit the secret description
#[arg(short = 'd', long)]
description: bool,
},

/// Delete a secret. Asks for confirmation
Delete {
/// The name of the secret
name: String,
},

/// Rename a secret
Rename {
/// The current name of the secret
name: String,

/// The new name of the secret. If blank, the user will be prompted for a new name
new_name: Option<String>,
},

/// List all secrets
List,

/// Create a new session token. Setting this token as `RUDRIC_SESSION` in the environment will
/// prevent the user from being prompted for the password each time the program is invoked.
Session(SessionArgs),

/// Read from the .renv file (or an alternate file) and set the specified variables in the environment.
/// This command generates the shell code necessary to set the requested
/// environment variables. The output of this command must be sourced with something like
/// `rudric env | source`
Env {
/// The shell format to use. Defaults to bash but a default can be specified in the config
/// file.
shell: Option<ShellType>,

/// Use an alternate environment file
#[arg(short, long)]
file: Option<String>,
},

/// Generate shell completions
GenerateCompletions {
/// The shell to generate completions for
shell: ShellType,
},

/// Change the master password for the vault
ChangePassword,
}

Expand All @@ -59,6 +105,8 @@ pub struct SessionArgs {

#[derive(Subcommand)]
pub enum SessionCmd {
/// Create a new session token
New,
/// Invalidates the current session token
End,
}
6 changes: 5 additions & 1 deletion src/command/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ pub async fn handle_session(config_dir: &Path, session_cmd: SessionArgs) -> Resu
Ok(())
}

pub async fn handle_env(config_dir: &Path, shell: Option<ShellType>) -> Result<()> {
pub async fn handle_env(
config_dir: &Path,
shell: Option<ShellType>,
file: Option<String>,
) -> Result<()> {
let app = App::new(config_dir, true).await?;
let config = Config::load(config_dir)?;

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async fn main() -> Result<()> {
Command::Session(session_cmd) => {
handle_session(&config_dir, session_cmd).await?;
}
Command::Env { shell } => {
handle_env(&config_dir, shell).await?;
Command::Env { shell, file } => {
handle_env(&config_dir, shell, file).await?;
}
Command::ChangePassword => {
handle_change_password(&config_dir).await?;
Expand Down

0 comments on commit 0139fc6

Please sign in to comment.