use std::path::PathBuf;
use clap::{Args, Subcommand, ValueEnum};
#[derive(Debug, Subcommand)]
pub enum TeamCommand {
#[command(
override_usage = "openmoat team join <BUNDLE> --signer \"<name> <key-type> <public-key>\"\n \
for example: openmoat team join ~/src/acme-openmoat \\\n \
--signer \"security@acme.example ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...\"",
after_help = TEAM_HELP
)]
Join(TeamJoinArgs),
#[command(after_help = TEAM_HELP)]
Update(TeamUpdateArgs),
#[command(after_help = TEAM_HELP)]
Leave,
}
const TEAM_HELP: &str = "\
The team publishes a folder (a git repository) with its rules, a manifest that names
each file's SHA-256, and the manifest's signature, made with:
ssh-keygen -Y sign -f <team key> -n openmoat-team-bundle openmoat-team.yaml
and its public key as one line, \"<name> <key-type> <public-key>\".
Each person, once:
git clone https://git.example.com/acme-openmoat ~/src/acme-openmoat
openmoat team join ~/src/acme-openmoat --signer \"security@acme.example ssh-ed25519 AAAA...\"
Later: git -C ~/src/acme-openmoat pull && openmoat team update
Check: openmoat inventory --check ~/src/acme-openmoat
Undo: openmoat team leave
Try it with a throwaway key, and the whole guide: docs/TEAM.md
(https://openmoat.dev/docs/team-rules/team-mode/)";
#[derive(Debug, Args)]
pub struct TeamJoinArgs {
pub bundle: PathBuf,
#[arg(long, value_name = "ENTRY")]
pub signer: String,
}
#[derive(Debug, Args)]
pub struct TeamUpdateArgs {
pub bundle: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum InventoryFormat {
Json,
Ocsf,
}
#[derive(Debug, Args)]
pub struct InventoryArgs {
#[arg(long, value_enum)]
pub format: Option<InventoryFormat>,
#[arg(long, value_name = "BUNDLE", conflicts_with = "deliver")]
pub check: Option<PathBuf>,
#[arg(long)]
pub deliver: bool,
}
#[cfg(test)]
mod tests {
use clap::{CommandFactory as _, Parser as _};
use crate::cli::Cli;
#[test]
fn join_without_arguments_shows_an_example() {
let error = Cli::try_parse_from(["openmoat", "team", "join"])
.unwrap_err()
.to_string();
assert!(error.contains("for example: openmoat team join"), "{error}");
let mut command = Cli::command();
let help = command
.find_subcommand_mut("team")
.and_then(|team| team.find_subcommand_mut("join"))
.unwrap()
.render_long_help()
.to_string();
assert!(help.contains("ssh-keygen -Y sign"), "{help}");
assert!(help.contains("docs/TEAM.md"), "{help}");
println!("{error}\n----\n{help}");
}
}