-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathremove.rs
More file actions
90 lines (74 loc) · 2.72 KB
/
Copy pathremove.rs
File metadata and controls
90 lines (74 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use anyhow::{Context, Result};
use clap::Parser;
use crate::commands::auth::resolve_access_token;
use crate::services::GraphNodeClient;
#[derive(Clone, Debug, Parser)]
#[clap(about = "Unregister a subgraph name from a Graph Node")]
pub struct RemoveOpt {
/// The subgraph name to unregister
#[clap(value_name = "SUBGRAPH_NAME")]
pub subgraph_name: String,
/// Graph Node admin URL
#[clap(long, short = 'g', value_name = "URL", help = "Graph Node URL")]
pub node: String,
/// Access token for authentication
#[clap(long, value_name = "TOKEN", help = "Graph access token")]
pub access_token: Option<String>,
}
/// Run the remove command
pub async fn run_remove(opt: RemoveOpt) -> Result<()> {
println!("Removing subgraph from Graph node: {}", opt.node);
// Get access token (from flag or from config)
let access_token = resolve_access_token(opt.access_token.as_deref(), &opt.node)?;
let client = GraphNodeClient::new(&opt.node, access_token.as_deref())
.context("Failed to create Graph Node client")?;
client
.remove_subgraph(&opt.subgraph_name)
.await
.context("Failed to remove subgraph")?;
println!("✔ Removed subgraph: {}", opt.subgraph_name);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_remove_opt_parsing() {
// Test that required args are enforced
let result = RemoveOpt::try_parse_from(["remove"]);
assert!(result.is_err());
// Test with just subgraph name (missing --node)
let result = RemoveOpt::try_parse_from(["remove", "user/subgraph"]);
assert!(result.is_err());
// Test with all required args
let result = RemoveOpt::try_parse_from([
"remove",
"user/subgraph",
"--node",
"http://localhost:8020",
]);
assert!(result.is_ok());
let opt = result.unwrap();
assert_eq!(opt.subgraph_name, "user/subgraph");
assert_eq!(opt.node, "http://localhost:8020");
assert!(opt.access_token.is_none());
// Test with access token
let result = RemoveOpt::try_parse_from([
"remove",
"user/subgraph",
"--node",
"http://localhost:8020",
"--access-token",
"my-token",
]);
assert!(result.is_ok());
let opt = result.unwrap();
assert_eq!(opt.access_token, Some("my-token".to_string()));
// Test short flag for node
let result =
RemoveOpt::try_parse_from(["remove", "user/subgraph", "-g", "http://localhost:8020"]);
assert!(result.is_ok());
let opt = result.unwrap();
assert_eq!(opt.node, "http://localhost:8020");
}
}