Skip to content

Feature: shell completion generation (bash, zsh, fish) #7

Description

@piranhap

Summary

opendotsync has no shell completions. Users must remember subcommand names and flags manually. Since the CLI is built with clap, completions are essentially free.

Implementation

Add a hidden completions <shell> subcommand using clap_complete:

# Cargo.toml
[dependencies]
clap_complete = "4"
// src/cli.rs
#[derive(Subcommand)]
pub enum Command {
    // ...
    /// Generate shell completions
    #[command(hide = true)]
    Completions { shell: clap_complete::Shell },
}
// src/main.rs dispatch
cli::Command::Completions { shell } => {
    clap_complete::generate(shell, &mut Cli::command(), "opendotsync", &mut std::io::stdout());
    Ok(())
}

Users install with:

# bash
opendotsync completions bash >> ~/.bashrc

# zsh
opendotsync completions zsh > ~/.zfunc/_opendotsync

# fish
opendotsync completions fish > ~/.config/fish/completions/opendotsync.fish

Affected Files

  • Cargo.toml — add clap_complete
  • src/cli.rs — add Completions variant
  • src/main.rs — wire dispatch

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions