-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4683 from wasmerio/gen-completions-manpages
Add subcommands to generate shell completions and manual pages
- Loading branch information
Showing
12 changed files
with
109 additions
and
12 deletions.
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 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 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 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 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 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 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,34 @@ | ||
use super::WasmerCmd; | ||
use clap::CommandFactory; | ||
use clap_complete::{generate, Shell}; | ||
use std::fs::OpenOptions; | ||
|
||
#[derive(Debug, Clone, clap::Parser)] | ||
pub struct CmdGenCompletions { | ||
/// The shell to generate the autocompletions script for. | ||
pub shell: Shell, | ||
|
||
/// Where to store the generated file(s) to. Defaults to stdout. | ||
#[clap(long)] | ||
pub out: Option<String>, | ||
} | ||
|
||
impl CmdGenCompletions { | ||
pub fn execute(&self) -> anyhow::Result<()> { | ||
let mut cmd = WasmerCmd::command(); | ||
|
||
let name = cmd.get_name().to_string(); | ||
if let Some(out) = &self.out { | ||
let mut f = OpenOptions::new() | ||
.truncate(true) | ||
.create(true) | ||
.write(true) | ||
.open(out)?; | ||
generate(self.shell, &mut cmd, name, &mut f); | ||
Ok(()) | ||
} else { | ||
generate(self.shell, &mut cmd, name, &mut std::io::stdout()); | ||
Ok(()) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use super::WasmerCmd; | ||
use anyhow::Context; | ||
use clap::CommandFactory; | ||
use clap_mangen::generate_to; | ||
use std::path::PathBuf; | ||
|
||
lazy_static::lazy_static! { | ||
static ref DEFAULT_MAN_DIR_PATH: PathBuf = dirs::data_dir().unwrap_or_default().join("man"); | ||
} | ||
|
||
#[derive(Debug, Clone, clap::Parser)] | ||
pub struct CmdGenManPage { | ||
/// Where to store the generated file(s) to. | ||
#[clap(long, default_value = DEFAULT_MAN_DIR_PATH.as_os_str())] | ||
pub out: PathBuf, | ||
} | ||
|
||
impl CmdGenManPage { | ||
pub fn execute(&self) -> anyhow::Result<()> { | ||
let cmd = WasmerCmd::command(); | ||
generate_to(cmd, &self.out).context(format!( | ||
"While generating the man page(s) to {}", | ||
self.out.display() | ||
)) | ||
} | ||
} |
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
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
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
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