Skip to content

Commit 64437b4

Browse files
committed
fix: Broken streams after naming refactor
1 parent 72348a4 commit 64437b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2572
-1731
lines changed

cli/src/api_client.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ impl std::fmt::Display for BuildStatus {
167167
impl BuildStatus {
168168
/// Returns true if this is a terminal state (no more transitions expected)
169169
pub fn is_terminal(&self) -> bool {
170-
matches!(self, BuildStatus::Completed | BuildStatus::Failed | BuildStatus::Cancelled)
170+
matches!(
171+
self,
172+
BuildStatus::Completed | BuildStatus::Failed | BuildStatus::Cancelled
173+
)
171174
}
172175
}
173176

@@ -279,8 +282,8 @@ pub struct StopDeploymentResponse {
279282

280283
impl ApiClient {
281284
pub fn new() -> Result<Self> {
282-
let base_url = std::env::var("HYPERSTACK_API_URL")
283-
.unwrap_or_else(|_| DEFAULT_API_URL.to_string());
285+
let base_url =
286+
std::env::var("HYPERSTACK_API_URL").unwrap_or_else(|_| DEFAULT_API_URL.to_string());
284287

285288
let api_key = Self::load_api_key().ok();
286289

@@ -522,7 +525,12 @@ impl ApiClient {
522525
}
523526

524527
/// List builds for the authenticated user, optionally filtered by spec_id
525-
pub fn list_builds_filtered(&self, limit: Option<i64>, offset: Option<i64>, spec_id: Option<i32>) -> Result<Vec<Build>> {
528+
pub fn list_builds_filtered(
529+
&self,
530+
limit: Option<i64>,
531+
offset: Option<i64>,
532+
spec_id: Option<i32>,
533+
) -> Result<Vec<Build>> {
526534
let api_key = self.require_api_key()?;
527535

528536
let mut url = format!("{}/api/builds", self.base_url);
@@ -591,7 +599,10 @@ impl ApiClient {
591599

592600
let response = self
593601
.client
594-
.get(format!("{}/api/deployments/{}", self.base_url, deployment_id))
602+
.get(format!(
603+
"{}/api/deployments/{}",
604+
self.base_url, deployment_id
605+
))
595606
.bearer_auth(api_key)
596607
.send()
597608
.context("Failed to send get deployment request")?;
@@ -606,7 +617,10 @@ impl ApiClient {
606617

607618
let response = self
608619
.client
609-
.delete(format!("{}/api/deployments/{}", self.base_url, deployment_id))
620+
.delete(format!(
621+
"{}/api/deployments/{}",
622+
self.base_url, deployment_id
623+
))
610624
.bearer_auth(api_key)
611625
.send()
612626
.context("Failed to send stop deployment request")?;
@@ -626,39 +640,34 @@ impl ApiClient {
626640
response: reqwest::blocking::Response,
627641
) -> Result<T> {
628642
if response.status().is_success() {
629-
response
630-
.json()
631-
.context("Failed to parse response JSON")
643+
response.json().context("Failed to parse response JSON")
632644
} else {
633645
let status = response.status();
634-
let error: ErrorResponse = response
635-
.json()
636-
.unwrap_or_else(|_| ErrorResponse {
637-
error: "Unknown error".to_string(),
638-
});
646+
let error: ErrorResponse = response.json().unwrap_or_else(|_| ErrorResponse {
647+
error: "Unknown error".to_string(),
648+
});
639649
anyhow::bail!("API error ({}): {}", status, error.error);
640650
}
641651
}
642652

643653
// Credentials management
644654

645655
fn credentials_path() -> Result<PathBuf> {
646-
let home = dirs::home_dir()
647-
.ok_or_else(|| anyhow::anyhow!("Could not find home directory"))?;
656+
let home =
657+
dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Could not find home directory"))?;
648658
Ok(home.join(".hyperstack").join("credentials.toml"))
649659
}
650660

651661
pub fn save_api_key(api_key: &str) -> Result<()> {
652662
let path = Self::credentials_path()?;
653-
663+
654664
// Create directory if it doesn't exist
655665
if let Some(parent) = path.parent() {
656666
fs::create_dir_all(parent)?;
657667
}
658668

659669
let content = format!("api_key = \"{}\"\n", api_key);
660-
fs::write(&path, content)
661-
.context("Failed to save API key")?;
670+
fs::write(&path, content).context("Failed to save API key")?;
662671

663672
Ok(())
664673
}
@@ -673,19 +682,17 @@ impl ApiClient {
673682
api_key: String,
674683
}
675684

676-
let creds: Credentials = toml::from_str(&content)
677-
.context("Failed to parse credentials file")?;
685+
let creds: Credentials =
686+
toml::from_str(&content).context("Failed to parse credentials file")?;
678687

679688
Ok(creds.api_key)
680689
}
681690

682691
pub fn delete_api_key() -> Result<()> {
683692
let path = Self::credentials_path()?;
684693
if path.exists() {
685-
fs::remove_file(&path)
686-
.context("Failed to delete credentials file")?;
694+
fs::remove_file(&path).context("Failed to delete credentials file")?;
687695
}
688696
Ok(())
689697
}
690698
}
691-

cli/src/commands/auth.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn register() -> Result<()> {
1010
print!("Username: ");
1111
use std::io::{self, Write};
1212
io::stdout().flush()?;
13-
13+
1414
let mut username = String::new();
1515
io::stdin().read_line(&mut username)?;
1616
let username = username.trim();
@@ -35,7 +35,7 @@ pub fn register() -> Result<()> {
3535
println!();
3636
println!("{}", "✓ Account created successfully!".green().bold());
3737
println!("Username: {}", response.user.username);
38-
38+
3939
if let Some(api_key) = &response.api_key {
4040
ApiClient::save_api_key(api_key)?;
4141
println!("{}", "✓ API key saved".green());
@@ -57,7 +57,7 @@ pub fn login() -> Result<()> {
5757
print!("Username: ");
5858
use std::io::{self, Write};
5959
io::stdout().flush()?;
60-
60+
6161
let mut username = String::new();
6262
io::stdin().read_line(&mut username)?;
6363
let username = username.trim();
@@ -73,7 +73,7 @@ pub fn login() -> Result<()> {
7373
println!();
7474
println!("{}", "✓ Login successful!".green().bold());
7575
println!("Username: {}", response.user.username);
76-
76+
7777
if let Some(api_key) = &response.api_key {
7878
ApiClient::save_api_key(api_key)?;
7979
println!("{}", "✓ API key saved".green());
@@ -87,9 +87,9 @@ pub fn login() -> Result<()> {
8787

8888
pub fn logout() -> Result<()> {
8989
println!("Logging out...");
90-
90+
9191
ApiClient::delete_api_key()?;
92-
92+
9393
println!("{}", "✓ Logged out successfully".green().bold());
9494
println!("Your credentials have been removed from this device.");
9595

@@ -103,11 +103,16 @@ pub fn status() -> Result<()> {
103103
println!();
104104
println!("You are logged in and ready to use Hyperstack.");
105105
println!();
106-
println!("API key location: {}",
106+
println!(
107+
"API key location: {}",
107108
ApiClient::new()
108109
.ok()
109110
.and_then(|_| dirs::home_dir())
110-
.map(|home| home.join(".hyperstack").join("credentials.toml").display().to_string())
111+
.map(|home| home
112+
.join(".hyperstack")
113+
.join("credentials.toml")
114+
.display()
115+
.to_string())
111116
.unwrap_or_else(|| "~/.hyperstack/credentials.toml".to_string())
112117
);
113118
}
@@ -136,18 +141,27 @@ pub fn whoami() -> Result<()> {
136141
println!("{} Verifying authentication...", "->".blue().bold());
137142

138143
let client = ApiClient::new()?;
139-
144+
140145
// Try to list specs as a way to verify the API key is valid
141146
match client.list_specs() {
142147
Ok(specs) => {
143148
println!("{}", "OK Authenticated".green().bold());
144149
println!();
145-
println!(" API key: {}...{}", &api_key[..8], &api_key[api_key.len()-4..]);
150+
println!(
151+
" API key: {}...{}",
152+
&api_key[..8],
153+
&api_key[api_key.len() - 4..]
154+
);
146155
println!(" Specs: {}", specs.len());
147156
println!();
148-
println!("API key location: {}",
157+
println!(
158+
"API key location: {}",
149159
dirs::home_dir()
150-
.map(|home| home.join(".hyperstack").join("credentials.toml").display().to_string())
160+
.map(|home| home
161+
.join(".hyperstack")
162+
.join("credentials.toml")
163+
.display()
164+
.to_string())
151165
.unwrap_or_else(|| "~/.hyperstack/credentials.toml".to_string())
152166
);
153167
}
@@ -162,4 +176,3 @@ pub fn whoami() -> Result<()> {
162176

163177
Ok(())
164178
}
165-

0 commit comments

Comments
 (0)