-
Notifications
You must be signed in to change notification settings - Fork 14
Make cargo-gpu a library, usable from build scripts #71
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a4f2502
build script: move Command run logic to `.run()`
Firestar99 f7aec7a
move usage dumping for readme to `mod dump_usage`
Firestar99 fb4795a
move testing utilities to `mod test`
Firestar99 ef6ad5c
turn cargo-gpu into a pure library
Firestar99 fd29217
recreate the binary and main function
Firestar99 a508ea7
fix clippy warnings
Firestar99 0893f06
make Install usable from a lib
Firestar99 16eb635
fix clippy
Firestar99 de3f89a
make dummy a library, skip linking an executable binary
Firestar99 30aac85
add logging on target-specs writing
Firestar99 5bb4db7
deduplicate cargo cloning rust-gpu due to slightly different url
Firestar99 409ecfd
change unreachable Err handling
Firestar99 c2d886d
make `Install` and `InstalledBackend` `#[non_exhaustive]`
Firestar99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Convenience function for internal use. Dumps all the CLI usage instructions. Useful for | ||
//! updating the README. | ||
|
||
use crate::{user_output, Cli}; | ||
|
||
/// main dump usage function | ||
pub fn dump_full_usage_for_readme() -> anyhow::Result<()> { | ||
use clap::CommandFactory as _; | ||
let mut command = Cli::command(); | ||
|
||
let mut buffer: Vec<u8> = Vec::default(); | ||
command.build(); | ||
|
||
write_help(&mut buffer, &mut command, 0)?; | ||
user_output!("{}", String::from_utf8(buffer)?); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Recursive function to print the usage instructions for each subcommand. | ||
fn write_help( | ||
buffer: &mut impl std::io::Write, | ||
cmd: &mut clap::Command, | ||
depth: usize, | ||
) -> anyhow::Result<()> { | ||
if cmd.get_name() == "help" { | ||
return Ok(()); | ||
} | ||
|
||
let mut command = cmd.get_name().to_owned(); | ||
let indent_depth = if depth == 0 || depth == 1 { 0 } else { depth }; | ||
let indent = " ".repeat(indent_depth * 4); | ||
writeln!( | ||
buffer, | ||
"\n{}* {}{}", | ||
indent, | ||
command.remove(0).to_uppercase(), | ||
command | ||
)?; | ||
|
||
for line in cmd.render_long_help().to_string().lines() { | ||
writeln!(buffer, "{indent} {line}")?; | ||
} | ||
|
||
for sub in cmd.get_subcommands_mut() { | ||
writeln!(buffer)?; | ||
write_help(buffer, sub, depth + 1)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.