Skip to content

Commit 30f0064

Browse files
gschierclaude
andauthored
CLI plugin host: handle send/render HTTP requests (#415)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3c12074 commit 30f0064

18 files changed

Lines changed: 1811 additions & 361 deletions

File tree

Cargo.lock

Lines changed: 118 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates-cli/yaak-cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ name = "yaak"
99
path = "src/main.rs"
1010

1111
[dependencies]
12+
arboard = "3"
1213
base64 = "0.22"
1314
clap = { version = "4", features = ["derive"] }
1415
console = "0.15"
1516
dirs = "6"
1617
env_logger = "0.11"
1718
futures = "0.3"
19+
inquire = { version = "0.7", features = ["editor"] }
1820
hex = { workspace = true }
1921
include_dir = "0.7"
2022
keyring = { workspace = true, features = ["apple-native", "windows-native", "sync-secret-service"] }

crates-cli/yaak-cli/src/cli.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pub struct Cli {
2121
#[arg(long, short, global = true)]
2222
pub environment: Option<String>,
2323

24+
/// Cookie jar ID to use when sending requests
25+
#[arg(long = "cookie-jar", global = true, value_name = "COOKIE_JAR_ID")]
26+
pub cookie_jar: Option<String>,
27+
2428
/// Enable verbose send output (events and streamed response body)
2529
#[arg(long, short, global = true)]
2630
pub verbose: bool,
@@ -58,6 +62,9 @@ pub enum Commands {
5862
/// Send a request, folder, or workspace by ID
5963
Send(SendArgs),
6064

65+
/// Cookie jar commands
66+
CookieJar(CookieJarArgs),
67+
6168
/// Workspace commands
6269
Workspace(WorkspaceArgs),
6370

@@ -85,6 +92,22 @@ pub struct SendArgs {
8592
pub fail_fast: bool,
8693
}
8794

95+
#[derive(Args)]
96+
#[command(disable_help_subcommand = true)]
97+
pub struct CookieJarArgs {
98+
#[command(subcommand)]
99+
pub command: CookieJarCommands,
100+
}
101+
102+
#[derive(Subcommand)]
103+
pub enum CookieJarCommands {
104+
/// List cookie jars in a workspace
105+
List {
106+
/// Workspace ID (optional when exactly one workspace exists)
107+
workspace_id: Option<String>,
108+
},
109+
}
110+
88111
#[derive(Args)]
89112
#[command(disable_help_subcommand = true)]
90113
pub struct WorkspaceArgs {
@@ -158,8 +181,8 @@ pub struct RequestArgs {
158181
pub enum RequestCommands {
159182
/// List requests in a workspace
160183
List {
161-
/// Workspace ID
162-
workspace_id: String,
184+
/// Workspace ID (optional when exactly one workspace exists)
185+
workspace_id: Option<String>,
163186
},
164187

165188
/// Show a request as JSON
@@ -267,8 +290,8 @@ pub struct FolderArgs {
267290
pub enum FolderCommands {
268291
/// List folders in a workspace
269292
List {
270-
/// Workspace ID
271-
workspace_id: String,
293+
/// Workspace ID (optional when exactly one workspace exists)
294+
workspace_id: Option<String>,
272295
},
273296

274297
/// Show a folder as JSON
@@ -324,8 +347,8 @@ pub struct EnvironmentArgs {
324347
pub enum EnvironmentCommands {
325348
/// List environments in a workspace
326349
List {
327-
/// Workspace ID
328-
workspace_id: String,
350+
/// Workspace ID (optional when exactly one workspace exists)
351+
workspace_id: Option<String>,
329352
},
330353

331354
/// Output JSON schema for environment create/update payloads
@@ -421,6 +444,9 @@ pub enum PluginCommands {
421444
/// Generate a "Hello World" Yaak plugin
422445
Generate(GenerateArgs),
423446

447+
/// Install a plugin from a local directory or from the registry
448+
Install(InstallPluginArgs),
449+
424450
/// Publish a Yaak plugin version to the plugin registry
425451
Publish(PluginPathArg),
426452
}
@@ -441,3 +467,9 @@ pub struct GenerateArgs {
441467
#[arg(long)]
442468
pub dir: Option<PathBuf>,
443469
}
470+
471+
#[derive(Args, Clone)]
472+
pub struct InstallPluginArgs {
473+
/// Local plugin directory path, or registry plugin spec (@org/plugin[@version])
474+
pub source: String,
475+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::cli::{CookieJarArgs, CookieJarCommands};
2+
use crate::context::CliContext;
3+
use crate::utils::workspace::resolve_workspace_id;
4+
5+
type CommandResult<T = ()> = std::result::Result<T, String>;
6+
7+
pub fn run(ctx: &CliContext, args: CookieJarArgs) -> i32 {
8+
let result = match args.command {
9+
CookieJarCommands::List { workspace_id } => list(ctx, workspace_id.as_deref()),
10+
};
11+
12+
match result {
13+
Ok(()) => 0,
14+
Err(error) => {
15+
eprintln!("Error: {error}");
16+
1
17+
}
18+
}
19+
}
20+
21+
fn list(ctx: &CliContext, workspace_id: Option<&str>) -> CommandResult {
22+
let workspace_id = resolve_workspace_id(ctx, workspace_id, "cookie-jar list")?;
23+
let cookie_jars = ctx
24+
.db()
25+
.list_cookie_jars(&workspace_id)
26+
.map_err(|e| format!("Failed to list cookie jars: {e}"))?;
27+
28+
if cookie_jars.is_empty() {
29+
println!("No cookie jars found in workspace {}", workspace_id);
30+
} else {
31+
for cookie_jar in cookie_jars {
32+
println!(
33+
"{} - {} ({} cookies)",
34+
cookie_jar.id,
35+
cookie_jar.name,
36+
cookie_jar.cookies.len()
37+
);
38+
}
39+
}
40+
41+
Ok(())
42+
}

0 commit comments

Comments
 (0)