Skip to content

Commit

Permalink
refactor: fixed clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jan 24, 2022
1 parent 9d2a729 commit 2f37374
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.
68 changes: 33 additions & 35 deletions packages/perseus-cli/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,62 +69,60 @@ fn build_server(
let sb_spinner = spinners.insert(num_steps - 1, ProgressBar::new_spinner());
let sb_spinner = cfg_spinner(sb_spinner, &sb_msg);
let sb_target = target;
let sb_thread =
spawn_thread(move || {
let (stdout, _stderr) = handle_exit_code!(run_stage(
let sb_thread = spawn_thread(move || {
let (stdout, _stderr) = handle_exit_code!(run_stage(
vec![&format!(
// This sets Cargo to tell us everything, including the executable path to the server
"{} build --message-format json {} {}",
"{} build --message-format json --features integration-{} {} --no-default-features {}",
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
// Enable the appropriate integration
format!(
"--features integration-{} {} --no-default-features",
integration.to_string(),
// We'll also handle whether or not it's standalone because that goes under the `--features` flag
if is_standalone {
"--features standalone"
} else {
""
}
),
integration.to_string(),
// We'll also handle whether or not it's standalone because that goes under the `--features` flag
if is_standalone {
"--features standalone"
} else {
""
},
if is_release { "--release" } else { "" },
)],
&sb_target,
&sb_spinner,
&sb_msg
)?);

let msgs: Vec<&str> = stdout.trim().split('\n').collect();
// If we got to here, the exit code was 0 and everything should've worked
// The last message will just tell us that the build finished, the second-last one will tell us the executable path
let msg = msgs.get(msgs.len() - 2);
let msg = match msg {
// We'll parse it as a Serde `Value`, we don't need to know everything that's in there
Some(msg) => serde_json::from_str::<serde_json::Value>(msg)
.map_err(|err| ExecutionError::GetServerExecutableFailed { source: err })?,
None => return Err(ExecutionError::ServerExectutableMsgNotFound),
};
let server_exec_path = msg.get("executable");
let server_exec_path = match server_exec_path {
let msgs: Vec<&str> = stdout.trim().split('\n').collect();
// If we got to here, the exit code was 0 and everything should've worked
// The last message will just tell us that the build finished, the second-last one will tell us the executable path
let msg = msgs.get(msgs.len() - 2);
let msg = match msg {
// We'll parse it as a Serde `Value`, we don't need to know everything that's in there
Some(msg) => serde_json::from_str::<serde_json::Value>(msg)
.map_err(|err| ExecutionError::GetServerExecutableFailed { source: err })?,
None => return Err(ExecutionError::ServerExectutableMsgNotFound),
};
let server_exec_path = msg.get("executable");
let server_exec_path = match server_exec_path {
// We'll parse it as a Serde `Value`, we don't need to know everything that's in there
Some(server_exec_path) => match server_exec_path.as_str() {
Some(server_exec_path) => server_exec_path,
None => return Err(ExecutionError::ParseServerExecutableFailed {
err: "expected 'executable' field to be string".to_string()
}),
None => {
return Err(ExecutionError::ParseServerExecutableFailed {
err: "expected 'executable' field to be string".to_string(),
})
}
},
None => return Err(ExecutionError::ParseServerExecutableFailed {
err: "expected 'executable' field in JSON map in second-last message, not present"
.to_string()
.to_string(),
}),
};

// And now the main thread needs to know about this
let mut exec_val = exec.lock().unwrap();
*exec_val = server_exec_path.to_string();
// And now the main thread needs to know about this
let mut exec_val = exec.lock().unwrap();
*exec_val = server_exec_path.to_string();

Ok(0)
});
Ok(0)
});

Ok(sb_thread)
}
Expand Down
7 changes: 2 additions & 5 deletions packages/perseus-cli/src/snoop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ pub fn snoop_server(dir: PathBuf, opts: SnoopServeOpts) -> Result<i32, Execution
let target = dir.join(".perseus/server");
run_cmd_directly(
format!(
"{} run {}",
"{} run --features integration-{} --no-default-features",
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
// Enable the appropriate feature for a non-default server integration
format!(
"--features integration-{} --no-default-features",
opts.integration.to_string()
)
opts.integration.to_string()
),
&target,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/server/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub async fn get_page_for_template<M: MutableStore, T: TranslationsManager>(
path = "index";
}
// Remove `/` from the path by encoding it as a URL (that's what we store) and add the locale
let path_encoded = format!("{}-{}", locale, urlencoding::encode(path).to_string());
let path_encoded = format!("{}-{}", locale, urlencoding::encode(path));
let path_with_locale = get_path_with_locale(path, &translator);

// Only a single string of HTML is needed, and it will be overridden if necessary (priorities system)
Expand Down
7 changes: 2 additions & 5 deletions packages/perseus/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ pub fn get_initial_state() -> InitialState {
Err(err) => ErrorPageData {
url: "[current]".to_string(),
status: 500,
err: format!(
"couldn't serialize error from server: '{}'",
err.to_string()
),
err: format!("couldn't serialize error from server: '{}'", err),
},
};
InitialState::Error(err_page_data)
Expand Down Expand Up @@ -407,7 +404,7 @@ pub async fn app_shell(
"{}/.perseus/page/{}/{}.json?template_name={}&was_incremental_match={}",
get_path_prefix_client(),
locale,
path.to_string(),
path,
template.get_path(),
was_incremental_match
);
Expand Down

0 comments on commit 2f37374

Please sign in to comment.