Skip to content

Support setting language and output directory in cargo xtask #2776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

egithinji
Copy link
Member

In addition to simplifying building locally (no need to set an environment variable), this makes it possible to use the cargo xtask build command in the CI and specify any output location, rather than relying on the build.sh script.

…serve commands.

In addition to simplifying building locally (no need to set an environment
variable), this makes it possible to use the `cargo xtask build` command in the CI
and specify any output location, rather than relying on the build.sh script.

/// Directory to place the build. If not provided, defaults to the book/ directory (or the book/xx directory if a language is provided).
#[arg(short, long)]
output: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use an Option<PathBuf> for better semantics. If we want to do anything with the provided path we would get a lot of methods for free if we have the correct semantic type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks didn't know Clap could accept PathBuf! This is much better.

if let Some(d) = output {
command.arg(d);
} else {
command.arg(format!("book/{}", language.unwrap_or("".to_string())));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good candidate for a Path otherwise we have directory separator issues e.g. with Windows

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -176,15 +204,29 @@ fn start_web_server() -> Result<()> {
Ok(())
}

fn build() -> Result<()> {
fn build(language: Option<String>, output: Option<String>) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PathBuf for consistency with the commandline args

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -156,15 +170,29 @@ fn run_rust_tests() -> Result<()> {
Ok(())
}

fn start_web_server() -> Result<()> {
fn start_web_server(language: Option<String>, output: Option<String>) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output: Option<Pathbuf> for consistency with the PathBuf in the arguments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants