forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
forc plugins
to emit file names only, with option of full pa…
…ths (FuelLabs#1381) * emit file names by default, with option of full path * pub use PluginsCommmand * cargo fmt * better handling of file_name * Use expect for print_plugin + add panic assumptions comment * Run forc-documenter for forc plugins Co-authored-by: bing <[email protected]>
- Loading branch information
bing
and
bing
authored
Apr 24, 2022
1 parent
fe4f296
commit a48a7e9
Showing
3 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
# forc-plugins | ||
Find all forc plugins available via `PATH`. | ||
|
||
Prints the absolute path to each discovered plugin on a new line. | ||
Prints information about each discovered plugin. | ||
|
||
|
||
## USAGE: | ||
forc plugins | ||
forc plugins [OPTIONS] | ||
|
||
|
||
## OPTIONS: | ||
|
||
`-h`, `--help` | ||
|
||
|
||
Print help information | ||
Print help information | ||
|
||
|
||
`-p`, `--paths` | ||
|
||
|
||
Prints the absolute path to each discovered plugin |
This file contains 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 |
---|---|---|
@@ -1,8 +1,43 @@ | ||
use crate::cli::PluginsCommand; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
|
||
/// Find all forc plugins available via `PATH`. | ||
/// | ||
/// Prints information about each discovered plugin. | ||
#[derive(Debug, Parser)] | ||
pub struct Command { | ||
/// Prints the absolute path to each discovered plugin. | ||
#[clap(long = "paths", short = 'p')] | ||
print_full_path: bool, | ||
} | ||
|
||
pub(crate) fn exec(command: PluginsCommand) -> Result<()> { | ||
let PluginsCommand { print_full_path } = command; | ||
|
||
pub(crate) fn exec() -> Result<()> { | ||
for path in crate::cli::plugin::find_all() { | ||
println!("{}", path.display()); | ||
print_plugin(path, print_full_path); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// # Panics | ||
/// | ||
/// This function assumes that file names will never be empty since it is only used with | ||
/// paths yielded from plugin::find_all(), as well as that the file names are in valid | ||
/// unicode format since file names should be prefixed with `forc-`. Should one of these 2 | ||
/// assumptions fail, this function panics. | ||
fn print_plugin(path: PathBuf, print_full_path: bool) { | ||
if print_full_path { | ||
println!("{}", path.display()); | ||
} else { | ||
println!( | ||
"{}", | ||
path.file_name() | ||
.expect("Failed to read file name") | ||
.to_str() | ||
.expect("Failed to print file name") | ||
); | ||
} | ||
} |
This file contains 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