Skip to content

Commit

Permalink
feat: shell completions (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: GetPsyched <[email protected]>
  • Loading branch information
prat24 and GetPsyched authored Jul 5, 2024
1 parent 60ba464 commit 659b796
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
chrono = "0.4.38"
clap = { version = "4.5.8", features = ["derive"] }
clap_complete = "4.5.7"
config = "0.14.0"
dirs = "5.0.1"
inquire = { version = "0.7.5", features = ["date"] }
Expand Down
16 changes: 16 additions & 0 deletions src/bin/todo/completion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::io;

use clap::{CommandFactory, Parser};
use clap_complete::{generate, Shell};

#[derive(Parser)]
pub struct Args {
#[clap(value_enum, help = "The shell to generate the completion script for")]
pub shell: Shell,
}

pub fn command(args: &Args) {
let mut command = crate::Args::command();
let binary_name = command.get_name().to_string();
generate(args.shell, &mut command, binary_name, &mut io::stdout());
}
5 changes: 5 additions & 0 deletions src/bin/todo/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use clap::{Parser, Subcommand};

mod completion;
mod create;
mod delete;
mod list;
mod show;
mod update;

#[derive(Parser)]
#[command(name = "todo")]
struct Args {
#[command(subcommand)]
command: Commands,
Expand All @@ -24,6 +26,8 @@ enum Commands {
Update(update::Args),
/// Delete a task
Delete(delete::Args),
/// Generate shell completion scripts
Completion(completion::Args),
}

fn main() {
Expand All @@ -35,5 +39,6 @@ fn main() {
Commands::Show(args) => show::command(args),
Commands::Update(args) => update::command(args),
Commands::Delete(args) => delete::command(args),
Commands::Completion(args) => completion::command(args),
}
}

0 comments on commit 659b796

Please sign in to comment.