-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2ea429
commit 1a0009b
Showing
5 changed files
with
77 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod collections; | ||
pub mod complete; | ||
pub mod generate; | ||
pub mod history; | ||
pub mod import; | ||
|
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 crate::{Args, GlobalArgs, Subcommand}; | ||
use anyhow::anyhow; | ||
use clap::{CommandFactory, Parser}; | ||
use clap_complete::Shell; | ||
use std::{io, process::ExitCode}; | ||
|
||
const COMMAND_NAME: &str = "slumber"; | ||
|
||
/// Generate shell completions | ||
#[derive(Clone, Debug, Parser)] | ||
pub struct CompleteCommand { | ||
/// Shell type. Default to $SHELL | ||
#[clap(long)] | ||
shell: Option<Shell>, | ||
} | ||
|
||
impl Subcommand for CompleteCommand { | ||
async fn execute(self, _: GlobalArgs) -> anyhow::Result<ExitCode> { | ||
let shell = self | ||
.shell | ||
.or_else(Shell::from_env) | ||
.ok_or_else(|| anyhow!("No shell provided and none detected"))?; | ||
let mut command = Args::command(); | ||
|
||
clap_complete::generate( | ||
shell, | ||
&mut command, | ||
COMMAND_NAME, | ||
&mut io::stdout(), | ||
); | ||
|
||
Ok(ExitCode::SUCCESS) | ||
} | ||
} |
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