Skip to content

Commit

Permalink
Autocomplete(*): Attempt to begin adding autocomplete support, leftwm#45
Browse files Browse the repository at this point in the history
  • Loading branch information
mautamu committed Jan 15, 2022
1 parent 5759bc9 commit 1eed93f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 38 deletions.
41 changes: 16 additions & 25 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 @@ -13,6 +13,7 @@ readme = "README.md"

[dependencies]
clap = { version = "3.0.0-beta.4", features=["derive"] }
clap_generate = {version = "3.0.0-beta.4"}
colored = "2.0.0"
dirs-next = "2.0.0"
edit-distance = "2.1.0"
Expand Down
37 changes: 24 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub mod utils;
use colored::Colorize;
use errors::{LeftErrorKind, Result};

use crate::models::Config;
use crate::models::{Config, Shell};
use crate::operations::{
Apply, Current, Install, List, New, Search, Status, Uninstall, Update, Upgrade,
};
use clap::Parser;
use clap::{IntoApp, Parser};
use log::error;
use std::env;

Expand All @@ -41,7 +41,9 @@ pub struct Opt {
pub verbose: u8,
/// Operation to be performed by the theme manager
#[clap(subcommand)]
pub operation: Operation,
pub operation: Option<Operation>,
#[clap(long, short, arg_enum, value_name="SHELL")]
pub completions: Option<Shell>
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -88,16 +90,25 @@ fn main() {

let wrapper: Result<()> = match opt.operation {
//Operation::AutoFind(args) => AutoFind::exec(&args),
Operation::Install(args) => Install::exec(&args, &mut config),
Operation::Uninstall(args) => Uninstall::exec(&args, &mut config),
Operation::List(args) => List::exec(&args, &mut config),
Operation::Apply(args) => Apply::exec(&args, &mut config),
Operation::Status(args) => Status::exec(&args, &mut config),
Operation::New(args) => New::exec(&args, &mut config),
Operation::Upgrade(args) => Upgrade::exec(&args, &mut config),
Operation::Update(args) => Update::exec(&args, &mut config),
Operation::Search(args) => Search::exec(&args, &mut config),
Operation::Current(args) => Current::exec(&args, &mut config),
Some(Operation::Install(args)) => Install::exec(&args, &mut config),
Some(Operation::Uninstall(args)) => Uninstall::exec(&args, &mut config),
Some(Operation::List(args)) => List::exec(&args, &mut config),
Some(Operation::Apply(args)) => Apply::exec(&args, &mut config),
Some(Operation::Status(args)) => Status::exec(&args, &mut config),
Some(Operation::New(args)) => New::exec(&args, &mut config),
Some(Operation::Upgrade(args)) => Upgrade::exec(&args, &mut config),
Some(Operation::Update(args)) => Update::exec(&args, &mut config),
Some(Operation::Search(args)) => Search::exec(&args, &mut config),
Some(Operation::Current(args)) => Current::exec(&args, &mut config),
None => {
if let Some(shell) = opt.completions {
let app = Opt::into_app();
shell.generate(app);
Ok(())
} else {
Err(errors::friendly_message("No command passed"))
}
}
};

if let Err(e) = wrapper {
Expand Down
2 changes: 2 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod config;
mod leftwm;
mod theme;
mod shells;

pub use config::{Config, Repo, THEMES_DIR};
pub use leftwm::LeftWm;
pub use theme::{DependencyL, Theme};
pub use shells::Shell;
26 changes: 26 additions & 0 deletions src/models/shells.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use clap::{App, ArgEnum};
use clap_generate::{generators::*, generate};

#[derive(ArgEnum, Copy, Clone, Debug)]
pub enum Shell {
Bash,
Zsh,
Fish,
PowerShell,
Elvish
}

impl Shell{
pub fn generate(&self, mut app: App) {
let mut fd = std::io::stdout();
match self{
Shell::Bash => generate::<Bash, _>(Bash, &mut app, "leftwm-theme", &mut fd),
Shell::Zsh => generate::<Zsh, _>(Zsh, &mut app, "leftwm-theme", &mut fd),
Shell::Fish => generate::<Fish, _>(Fish, &mut app, "leftwm-theme", &mut fd),
Shell::PowerShell => generate::<PowerShell, _>(PowerShell, &mut app, "leftwm-theme", &mut fd),
Shell::Elvish => generate::<Elvish, _>(Elvish, &mut app, "leftwm-theme", &mut fd),
}
}
}


0 comments on commit 1eed93f

Please sign in to comment.