framesmith-cli 0.1.0

CLI tool for controlling Samsung Frame TVs over the local network
use std::io;

use anyhow::Result;
use clap::CommandFactory;
use clap_complete::{Shell, generate};

use crate::cli::CompletionCli;

pub fn run(shell: Option<Shell>) -> Result<()> {
    match shell {
        Some(shell) => {
            let mut cmd = CompletionCli::command();
            generate(shell, &mut cmd, "framesmith", &mut io::stdout());
        }
        None => {
            print_setup_instructions();
        }
    }
    Ok(())
}

fn print_setup_instructions() {
    println!("Generate shell completions for framesmith.");
    println!();
    println!("USAGE:");
    println!("  framesmith completions <SHELL>");
    println!();
    println!("SUPPORTED SHELLS: bash, zsh, fish, powershell");
    println!();
    println!("SETUP INSTRUCTIONS:");
    println!();
    println!("  Bash:");
    println!(
        "    framesmith completions bash > ~/.local/share/bash-completion/completions/framesmith"
    );
    println!();
    println!("  Zsh:");
    println!("    framesmith completions zsh > ~/.zfunc/_framesmith");
    println!("    # Then add to ~/.zshrc: fpath+=~/.zfunc; autoload -Uz compinit && compinit");
    println!();
    println!("  Fish:");
    println!("    framesmith completions fish > ~/.config/fish/completions/framesmith.fish");
    println!();
    println!("  PowerShell:");
    println!("    framesmith completions powershell >> $PROFILE");
}