Skip to content

Commit

Permalink
Upgrade to clap v3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza committed Feb 16, 2022
1 parent 66d882b commit b3366dd
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 85 deletions.
83 changes: 55 additions & 28 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ members = ["xtask/"]
anyhow = "1.0.32"
askama = { version = "0.11.0", default-features = false }
bincode = "1.3.1"
clap = { version = "3.0.0", features = ["derive"] }
clap = { version = "3.1.0", features = ["derive"] }
dirs = "4.0.0"
dunce = "1.0.1"
glob = "0.3.0"
Expand All @@ -36,9 +36,9 @@ rand = { version = "0.8.4", features = [
], default-features = false }

[build-dependencies]
clap = { version = "3.0.0", features = ["derive"] }
clap_complete = "3.0.0"
clap_complete_fig = "3.0.0"
clap = { version = "3.1.0", features = ["derive"] }
clap_complete = "3.1.0"
clap_complete_fig = "3.1.0"

[dev-dependencies]
assert_cmd = "2.0.0"
Expand Down
24 changes: 12 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ fn git_version() -> Option<String> {
}

fn generate_completions() -> io::Result<()> {
#[path = "src/app/_app.rs"]
mod app;
#[path = "src/cmd/_cmd.rs"]
mod cmd;

use app::App;
use clap::IntoApp;
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::Shell::{Bash, Elvish, Fish, PowerShell, Zsh};
use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh};
use clap_complete_fig::Fig;
use cmd::Cmd;

let app = &mut App::into_app();
let cmd = &mut Cmd::command();
let bin_name = env!("CARGO_PKG_NAME");
let out_dir = "contrib/completions";

generate_to(Bash, app, bin_name, out_dir)?;
generate_to(Elvish, app, bin_name, out_dir)?;
generate_to(Fig, app, bin_name, out_dir)?;
generate_to(Fish, app, bin_name, out_dir)?;
generate_to(PowerShell, app, bin_name, out_dir)?;
generate_to(Zsh, app, bin_name, out_dir)?;
generate_to(Bash, cmd, bin_name, out_dir)?;
generate_to(Elvish, cmd, bin_name, out_dir)?;
generate_to(Fig, cmd, bin_name, out_dir)?;
generate_to(Fish, cmd, bin_name, out_dir)?;
generate_to(PowerShell, cmd, bin_name, out_dir)?;
generate_to(Zsh, cmd, bin_name, out_dir)?;

Ok(())
}
3 changes: 2 additions & 1 deletion contrib/completions/_zoxide.ps1

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

26 changes: 0 additions & 26 deletions src/app/mod.rs

This file was deleted.

8 changes: 4 additions & 4 deletions src/app/_app.rs → src/cmd/_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use clap::{AppSettings, ArgEnum, Parser, ValueHint};
use clap::{ArgEnum, Parser, ValueHint};

const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
_ZO_DATA_DIR Path for zoxide data files
Expand All @@ -16,11 +16,11 @@ const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
about,
author,
after_help = ENV_HELP,
global_setting(AppSettings::DisableHelpSubcommand),
global_setting(AppSettings::PropagateVersion),
disable_help_subcommand = true,
propagate_version = true,
version = option_env!("ZOXIDE_VERSION").unwrap_or_default()
)]
pub enum App {
pub enum Cmd {
Add(Add),
Import(Import),
Init(Init),
Expand Down
2 changes: 1 addition & 1 deletion src/app/add.rs → src/cmd/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;

use anyhow::{bail, Result};

use crate::app::{Add, Run};
use crate::cmd::{Add, Run};
use crate::db::DatabaseFile;
use crate::{config, util};

Expand Down
2 changes: 1 addition & 1 deletion src/app/import.rs → src/cmd/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs;

use anyhow::{bail, Context, Result};

use crate::app::{Import, ImportFrom, Run};
use crate::cmd::{Import, ImportFrom, Run};
use crate::config;
use crate::db::{Database, DatabaseFile, Dir};

Expand Down
2 changes: 1 addition & 1 deletion src/app/init.rs → src/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{self, Write};
use anyhow::{Context, Result};
use askama::Template;

use crate::app::{Init, InitShell, Run};
use crate::cmd::{Init, InitShell, Run};
use crate::config;
use crate::error::BrokenPipeHandler;
use crate::shell::{self, Opts};
Expand Down
26 changes: 26 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
mod _cmd;
mod add;
mod import;
mod init;
mod query;
mod remove;

use anyhow::Result;

pub use crate::cmd::_cmd::*;

pub trait Run {
fn run(&self) -> Result<()>;
}

impl Run for Cmd {
fn run(&self) -> Result<()> {
match self {
Cmd::Add(cmd) => cmd.run(),
Cmd::Import(cmd) => cmd.run(),
Cmd::Init(cmd) => cmd.run(),
Cmd::Query(cmd) => cmd.run(),
Cmd::Remove(cmd) => cmd.run(),
}
}
}
2 changes: 1 addition & 1 deletion src/app/query.rs → src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{self, Write};

use anyhow::{Context, Result};

use crate::app::{Query, Run};
use crate::cmd::{Query, Run};
use crate::db::{Database, DatabaseFile};
use crate::error::BrokenPipeHandler;
use crate::fzf::Fzf;
Expand Down
2 changes: 1 addition & 1 deletion src/app/remove.rs → src/cmd/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{self, Write};

use anyhow::{bail, Context, Result};

use crate::app::{Remove, Run};
use crate::cmd::{Remove, Run};
use crate::db::DatabaseFile;
use crate::fzf::Fzf;
use crate::{config, util};
Expand Down
Loading

0 comments on commit b3366dd

Please sign in to comment.