Skip to content

Commit 882fa7c

Browse files
committed
readability
1 parent 7034cf0 commit 882fa7c

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

crates/cli/src/subcommands/publish.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,16 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
147147
let mut builder = client.put(format!("{database_host}/v1/database/{domain}"));
148148

149149
if !clear_database {
150-
if let Some(pre_publish_res) = call_pre_publish(
150+
builder = apply_pre_publish_if_needed(
151+
builder,
151152
&client,
152153
&database_host,
153154
&domain.to_string(),
154155
&program_bytes,
155156
&auth_header,
157+
break_clients_flag,
156158
)
157-
.await?
158-
{
159-
println!("{}", pre_publish_res.migrate_plan);
160-
if pre_publish_res.break_clients
161-
&& !y_or_n(
162-
break_clients_flag,
163-
"The above changes will BREAK existing clients. Do you want to proceed?",
164-
)?
165-
{
166-
println!("Aborting");
167-
return Ok(());
168-
}
169-
170-
builder = builder.query(&[("token", pre_publish_res.token)]);
171-
builder = builder.query(&[("policy", "BreakClients")]);
172-
}
159+
.await?;
173160
};
174161

175162
builder
@@ -266,6 +253,39 @@ pub fn pretty_print_style_from_env() -> PrettyPrintStyle {
266253
}
267254
}
268255

256+
/// Applies pre-publish logic: checking for migration plan, prompting user, and
257+
/// modifying the request builder accordingly.
258+
async fn apply_pre_publish_if_needed(
259+
mut builder: reqwest::RequestBuilder,
260+
client: &reqwest::Client,
261+
base_url: &str,
262+
domain: &String,
263+
program_bytes: &[u8],
264+
auth_header: &AuthHeader,
265+
break_clients_flag: bool,
266+
) -> Result<reqwest::RequestBuilder, anyhow::Error> {
267+
if let Some(pre) = call_pre_publish(client, base_url, &domain.to_string(), program_bytes, auth_header).await? {
268+
println!("{}", pre.migrate_plan);
269+
270+
if pre.break_clients
271+
&& !y_or_n(
272+
break_clients_flag,
273+
"The above changes will BREAK existing clients. Do you want to proceed?",
274+
)?
275+
{
276+
println!("Aborting");
277+
// Early exit: return an error or a special signal. Here we bail out by returning Err.
278+
return Err(anyhow::anyhow!("Publishing aborted by user"));
279+
}
280+
281+
builder = builder
282+
.query(&[("token", pre.token)])
283+
.query(&[("policy", "BreakClients")]);
284+
}
285+
286+
Ok(builder)
287+
}
288+
269289
async fn call_pre_publish(
270290
client: &reqwest::Client,
271291
database_host: &str,

0 commit comments

Comments
 (0)