|
1 | 1 | use anyhow::Result; |
| 2 | +use serde_json::json; |
| 3 | +use colored::Colorize; |
2 | 4 | use crate::format; |
3 | 5 | use crate::warp_cli; |
| 6 | +use crate::ip; |
4 | 7 |
|
5 | 8 | pub fn run(connect: bool, json: bool, quiet: bool) -> Result<()> { |
6 | 9 | if connect { |
| 10 | + // Get IP before connecting |
| 11 | + let before_ip = ip::get_public_ip().ok(); |
| 12 | + |
7 | 13 | warp_cli::connect()?; |
8 | | - format::success(json, quiet, "✓ Connected to WARP"); |
| 14 | + |
| 15 | + // Get IP after connecting |
| 16 | + let after_ip = ip::get_public_ip().ok(); |
| 17 | + |
| 18 | + if json { |
| 19 | + let obj = json!({ |
| 20 | + "status": "success", |
| 21 | + "message": "Connected to WARP", |
| 22 | + "before_ip": before_ip, |
| 23 | + "after_ip": after_ip |
| 24 | + }); |
| 25 | + if !quiet { |
| 26 | + println!("{}", obj.to_string()); |
| 27 | + } |
| 28 | + } else { |
| 29 | + if !quiet { |
| 30 | + format::success(false, false, "✓ Connected to WARP"); |
| 31 | + if let Some(ref before) = before_ip { |
| 32 | + println!(" Before: {}", before.cyan()); |
| 33 | + } |
| 34 | + if let Some(ref after) = after_ip { |
| 35 | + println!(" After: {}", after.green()); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
9 | 39 | } else { |
| 40 | + // Get IP before disconnecting |
| 41 | + let before_ip = ip::get_public_ip().ok(); |
| 42 | + |
10 | 43 | warp_cli::disconnect()?; |
11 | | - format::success(json, quiet, "✓ Disconnected from WARP"); |
| 44 | + |
| 45 | + // Get IP after disconnecting |
| 46 | + let after_ip = ip::get_public_ip().ok(); |
| 47 | + |
| 48 | + if json { |
| 49 | + let obj = json!({ |
| 50 | + "status": "success", |
| 51 | + "message": "Disconnected from WARP", |
| 52 | + "before_ip": before_ip, |
| 53 | + "after_ip": after_ip |
| 54 | + }); |
| 55 | + if !quiet { |
| 56 | + println!("{}", obj.to_string()); |
| 57 | + } |
| 58 | + } else { |
| 59 | + if !quiet { |
| 60 | + format::success(false, false, "✓ Disconnected from WARP"); |
| 61 | + if let Some(ref before) = before_ip { |
| 62 | + println!(" Before: {}", before.cyan()); |
| 63 | + } |
| 64 | + if let Some(ref after) = after_ip { |
| 65 | + println!(" After: {}", after.green()); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
12 | 69 | } |
13 | 70 |
|
14 | 71 | Ok(()) |
|
0 commit comments