Skip to content

Commit 432a4ae

Browse files
committed
re-organize for symmetry
1 parent 084157c commit 432a4ae

File tree

6 files changed

+58
-32
lines changed

6 files changed

+58
-32
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ tonic-build = { version = "0.13", default-features = false, features = ["prost"]
8383
walkdir = { version = "2.5", default-features = false }
8484

8585
# Environment and configuration
86-
dialoguer = { version = "0.11", default-features = false }
8786
dotenvy = { version = "0.15.0", default-features = false }
8887
clap = { version = "4.5", features = ["std", "derive", "help", "usage", "error-context"], default-features = false }
8988

tvc/src/cli.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ pub struct GlobalConfig {
1010
pub api_base_url: String,
1111
}
1212

13-
/// CLI command parsing and dispatch
13+
/// CLI command parsing and dispatch.
1414
#[derive(Debug, Parser)]
1515
#[command(about = "CLI for building with Turnkey Verifiable Cloud", long_about = None)]
1616
pub struct Cli {
17-
/// Turnkey organization ID
17+
/// Turnkey organization ID.
1818
#[arg(long, global = true, env = "TVC_ORGANIZATION_ID")]
1919
pub organization_id: Option<String>,
2020

21-
/// API base URL
21+
/// API base URL.
2222
#[arg(
2323
long,
2424
global = true,
@@ -32,7 +32,7 @@ pub struct Cli {
3232
}
3333

3434
impl Cli {
35-
/// Run the CLI
35+
/// Run the CLI.
3636
pub async fn run() -> anyhow::Result<()> {
3737
let args = Cli::parse();
3838

@@ -42,12 +42,14 @@ impl Cli {
4242
};
4343

4444
match args.command {
45-
Commands::ApproveManifest(cmd_args) => commands::approve::run(cmd_args, &config).await,
45+
Commands::ApproveManifest(cmd_args) => {
46+
commands::approve_manifest::run(cmd_args, &config).await
47+
}
4648
}
4749
}
4850
}
4951

5052
#[derive(Debug, Subcommand)]
5153
enum Commands {
52-
ApproveManifest(commands::approve::ApproveManifest),
54+
ApproveManifest(commands::approve_manifest::Args),
5355
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ use crate::pair::LocalPair;
44
use crate::util::{read_file_to_string, write_file};
55
use anyhow::anyhow;
66
use anyhow::{bail, Context};
7-
use clap::{ArgGroup, Args};
7+
use clap::{ArgGroup, Args as ClapArgs};
88
use qos_core::protocol::services::boot::Approval;
99
use qos_core::protocol::services::boot::{
1010
Manifest, ManifestSet, Namespace, NitroConfig, PivotConfig, QuorumMember, ShareSet,
1111
};
1212
use qos_core::protocol::QosHash;
13+
use std::io::{BufRead, Write};
1314
use std::path::Path;
1415
use std::path::PathBuf;
15-
use std::io::{BufRead, Write};
1616

17-
/// Approve a QOS manifest
18-
#[derive(Debug, Args)]
17+
/// Approve a QOS manifest.
18+
#[derive(Debug, ClapArgs)]
1919
#[command(about, long_about = None)]
2020
#[command(group(ArgGroup::new("operator").args(["operator_seed", "operator_id"])))]
2121
#[command(group(ArgGroup::new("manifest-source").args(["manifest", "deploy_id"])))]
22-
pub struct ApproveManifest {
22+
pub struct Args {
2323
/// Path to QOS manifest file.
2424
#[arg(
2525
short,
@@ -29,7 +29,7 @@ pub struct ApproveManifest {
2929
)]
3030
pub manifest: Option<PathBuf>,
3131

32-
/// ID of the deployment the manifest belongs to
32+
/// ID of the deployment the manifest belongs to.
3333
#[arg(
3434
short,
3535
long,
@@ -38,41 +38,41 @@ pub struct ApproveManifest {
3838
)]
3939
pub deploy_id: Option<String>,
4040

41-
/// Path to the file containing the master seed for the operator key
41+
/// Path to the file containing the master seed for the operator key.
4242
#[arg(
4343
long,
4444
help_heading = "Operator to approve with (pick one)",
4545
value_name = "PATH"
4646
)]
4747
pub operator_seed: Option<PathBuf>,
4848

49-
/// Operator ID to use
49+
/// Operator ID to use.
5050
#[arg(
5151
long,
5252
help_heading = "Operator to approve with (pick one)",
5353
env = "TVC_OPERATOR_ID"
5454
)]
5555
pub operator_id: Option<String>,
5656

57-
/// Walk through manifest approval prompts but do not generate an approval
57+
/// Walk through manifest approval prompts but do not generate an approval.
5858
#[arg(long)]
5959
pub dry_run: bool,
6060

61-
/// DANGEROUS: skip interactive prompts for approving each aspect of manifest
61+
/// DANGEROUS: skip interactive prompts for approving each aspect of manifest.
6262
#[arg(long)]
6363
pub dangerous_skip_interactive: bool,
6464

65-
/// Write approval to file instead of stdout
65+
/// Write approval to file instead of stdout.
6666
#[arg(short, long, value_name = "PATH")]
6767
pub output: Option<PathBuf>,
6868

69-
/// Don't post approval to the API
69+
/// Don't post approval to the API.
7070
#[arg(long)]
7171
pub skip_post: bool,
7272
}
7373

7474
/// Run the approve manifest command.
75-
pub async fn run(args: ApproveManifest, _config: &crate::cli::GlobalConfig) -> anyhow::Result<()> {
75+
pub async fn run(args: Args, _config: &crate::cli::GlobalConfig) -> anyhow::Result<()> {
7676
let manifest = match (&args.manifest, &args.deploy_id) {
7777
(Some(path), _) => read_manifest_from_path(path).await?,
7878
(_, Some(deploy_id)) => fetch_manifest_from_deploy(deploy_id).await?,

tvc/src/commands/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
//! CLI commands.
22
//!
33
//! Each command module should contain:
4-
//! - An args struct deriving `clap::Args`
4+
//! - An `Args` struct deriving `clap::Args`
55
//! - A `run(args) -> anyhow::Result<()>` function
6-
//!
7-
//! To add a new command:
8-
//! 1. Create a new module file (e.g., `verify.rs`)
9-
//! 2. Define your args struct and `run` function
10-
//! 3. Add `pub mod verify;` below
11-
//! 4. Add the command variant to `Commands` enum in `cli.rs`
12-
//! 5. Add the match arm in `Cli::run()`
136
14-
pub mod approve;
7+
pub mod approve_manifest;

tvc/src/pair.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::path::Path;
66
use std::pin::Pin;
77
use std::sync::Arc;
88

9-
/// Something that can do key pair operations with the qos p256 scheme.
9+
/// Something that can do key pair operations with the QOS p256 scheme.
1010
pub trait Pair: Send + Sync {
11-
/// Sign the given message. This method will compute the digest before signing.
11+
/// Sign the given message.
1212
fn sign(
1313
&self,
1414
message: Vec<u8>,
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn approve_manifest_requires_source() {
1313
}
1414

1515
#[test]
16-
fn approve_manifest_with_file() {
16+
fn dangerous_approve_manifest_with_file() {
1717
cargo_bin_cmd!("tvc")
1818
.arg("approve-manifest")
1919
.arg("--manifest")
@@ -70,3 +70,35 @@ fn approve_manifest_interactive_reject() {
7070
.failure()
7171
.stderr(predicate::str::contains("approval cancelled by user"));
7272
}
73+
74+
#[test]
75+
fn manifest_and_deploy_id_are_mutually_exclusive() {
76+
cargo_bin_cmd!("tvc")
77+
.arg("approve-manifest")
78+
.arg("--manifest")
79+
.arg("fixtures/manifest.json")
80+
.arg("--deploy-id")
81+
.arg("some-deploy-id")
82+
.arg("--dangerous-skip-interactive")
83+
.assert()
84+
.failure()
85+
.stderr(predicate::str::contains(
86+
"the argument '--manifest <PATH>' cannot be used with '--deploy-id <DEPLOY_ID>'",
87+
));
88+
}
89+
90+
#[test]
91+
fn operator_seed_and_operator_id_are_mutually_exclusive() {
92+
cargo_bin_cmd!("tvc")
93+
.arg("approve-manifest")
94+
.arg("--manifest")
95+
.arg("fixtures/manifest.json")
96+
.arg("--operator-seed")
97+
.arg("fixtures/seed.hex")
98+
.arg("--operator-id")
99+
.arg("some-operator-id")
100+
.arg("--dangerous-skip-interactive")
101+
.assert()
102+
.failure()
103+
.stderr(predicate::str::contains("the argument '--operator-seed <PATH>' cannot be used with '--operator-id <OPERATOR_ID>'"));
104+
}

0 commit comments

Comments
 (0)