1
0
Fork 0

Fix command name in cargo nih-plug usage string

This commit is contained in:
Robbert van der Helm 2022-03-02 10:34:50 +01:00
parent bb7a1c3586
commit 85ea65c080
2 changed files with 16 additions and 11 deletions

View file

@ -2,5 +2,5 @@ fn main() -> nih_plug_xtask::Result<()> {
// This includes both the `cargo` command and the `nih-plug` subcommand, so we should get rid of // This includes both the `cargo` command and the `nih-plug` subcommand, so we should get rid of
// those first // those first
let args = std::env::args().skip(2); let args = std::env::args().skip(2);
nih_plug_xtask::main_with_args(args) nih_plug_xtask::main_with_args("cargo nih-plug", args)
} }

View file

@ -10,13 +10,17 @@ mod symbols;
/// Re-export for the main function. /// Re-export for the main function.
pub use anyhow::Result; pub use anyhow::Result;
const USAGE_STRING: &str = "Usage:
cargo xtask bundle <package> [--release] [--target <triple>]
cargo xtask bundle -p <package1> -p <package2> ... [--release] [--target <triple>]";
/// The base birectory for the bundler's output. /// The base birectory for the bundler's output.
const BUNDLE_HOME: &str = "target/bundled"; const BUNDLE_HOME: &str = "target/bundled";
fn build_usage_string(command_name: &str) -> String {
format!(
"Usage:
{command_name} bundle <package> [--release] [--target <triple>]
{command_name} bundle -p <package1> -p <package2> ... [--release] [--target <triple>]"
)
}
/// Any additional configuration that might be useful for creating plugin bundles, stored as /// Any additional configuration that might be useful for creating plugin bundles, stored as
/// `bundler.toml` alongside the workspace's main `Cargo.toml` file. /// `bundler.toml` alongside the workspace's main `Cargo.toml` file.
type BundlerConfig = HashMap<String, PackageConfig>; type BundlerConfig = HashMap<String, PackageConfig>;
@ -44,18 +48,19 @@ pub enum CompilationTarget {
/// The main xtask entry point function. See the readme for instructions on how to use this. /// The main xtask entry point function. See the readme for instructions on how to use this.
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let args = std::env::args().skip(1); let args = std::env::args().skip(1);
main_with_args(args) main_with_args("cargo xtask", args)
} }
/// The main xtask entry point function, but with custom command line arguments. `args` should not /// The main xtask entry point function, but with custom command line arguments. `args` should not
/// contain the command name, so you should always skip at least one argument from /// contain the command name, so you should always skip at least one argument from
/// `std::env::args()` before passing it to this function. /// `std::env::args()` before passing it to this function.
pub fn main_with_args(mut args: impl Iterator<Item = String>) -> Result<()> { pub fn main_with_args(command_name: &str, mut args: impl Iterator<Item = String>) -> Result<()> {
chdir_workspace_root()?; chdir_workspace_root()?;
let usage_string = build_usage_string(command_name);
let command = args let command = args
.next() .next()
.context(format!("Missing command name\n\n{USAGE_STRING}"))?; .context(format!("Missing command name\n\n{usage_string}",))?;
match command.as_str() { match command.as_str() {
"bundle" => { "bundle" => {
// For convenience's sake we'll allow building multiple packages with -p just like carg // For convenience's sake we'll allow building multiple packages with -p just like carg
@ -66,13 +71,13 @@ pub fn main_with_args(mut args: impl Iterator<Item = String>) -> Result<()> {
while args.peek().map(|s| s.as_str()) == Some("-p") { while args.peek().map(|s| s.as_str()) == Some("-p") {
packages.push( packages.push(
args.nth(1) args.nth(1)
.context(format!("Missing package name after -p\n\n{USAGE_STRING}"))?, .context(format!("Missing package name after -p\n\n{usage_string}"))?,
); );
} }
} else { } else {
packages.push( packages.push(
args.next() args.next()
.context(format!("Missing package name\n\n{USAGE_STRING}"))?, .context(format!("Missing package name\n\n{usage_string}"))?,
); );
}; };
let other_args: Vec<_> = args.collect(); let other_args: Vec<_> = args.collect();
@ -88,7 +93,7 @@ pub fn main_with_args(mut args: impl Iterator<Item = String>) -> Result<()> {
// This is only meant to be used by the CI, since using awk for this can be a bit spotty on // This is only meant to be used by the CI, since using awk for this can be a bit spotty on
// macOS // macOS
"known-packages" => list_known_packages(), "known-packages" => list_known_packages(),
_ => bail!("Unknown command '{command}'\n\n{USAGE_STRING}"), _ => bail!("Unknown command '{command}'\n\n{usage_string}"),
} }
} }