Skip to content

Commit

Permalink
Merge branch 'main' into no-self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
tippfehlr authored Mar 27, 2024
2 parents 2d31819 + cf111e6 commit f1e03ab
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 288 deletions.
90 changes: 51 additions & 39 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wrestic"
version = "1.5.0"
version = "1.6.1"
authors = ["alvaro17f"]
description = "Restic wrapper built in Rust"
homepage = "https://wrestic.com/"
Expand All @@ -10,23 +10,23 @@ edition = "2021"
keywords = ["restic", "wrapper", "rust", "backup", "tool"]

[dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.18", features = ["derive"] }
clap_complete = "4.4.7"
anyhow = "1.0.81"
clap = { version = "4.5.4", features = ["derive"] }
clap_complete = "4.5.1"
cmd_lib = "1.9.3"
color-print = "0.3.5"
config = "0.13.4"
dialoguer = "0.11.0"
flate2 = "1.0.28"
indicatif = "0.17.7"
indicatif = "0.17.8"
lazy_static = "1.4.0"
nix = { version = "0.27.1", features = ["user"] }
regex = "1.10.2"
serde = "1.0.195"
serde_json = "1.0.111"
nix = { version = "0.28.0", features = ["user"] }
regex = "1.10.4"
serde = "1.0.197"
serde_json = "1.0.115"
sudo = "0.6.0"
tar = "0.4.40"
which = "6.0.0"
which = "6.0.1"

[features]
no-self-update = []
44 changes: 16 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
mod modules;
mod utils;

use crate::utils::{
completions::set_completions, set_environment_variables::set_environment_variables,
tools::clear,
};
use crate::utils::{set_environment_variables::set_environment_variables, tools::clear};
use anyhow::Result;
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
Expand All @@ -15,17 +12,11 @@ use modules::{
initialize::initialize, repair::repair, restore::restore, selector::selector,
snapshots::snapshots, update::update,
};
use std::process::exit;
use utils::{
completions::print_completions, get_config::get_config, restic_checker::restic_checker,
};
use utils::{get_config::get_config, restic_checker::restic_checker};

#[derive(Parser, Debug, PartialEq)]
#[command(author, version, about, long_about = None)]
struct Cli {
// If provided, generate completions for given shell
#[arg(long = "generate", value_enum)]
generator: Option<Shell>,
/// List of available commands
#[command(subcommand)]
commands: Option<Commands>,
Expand Down Expand Up @@ -61,21 +52,11 @@ enum Commands {
#[clap(short_flag = 'c', allow_hyphen_values = true)]
#[command(arg_required_else_help = true)]
Custom { args: Vec<String> },
}

fn handle_completions(cli: &Cli) -> Result<()> {
if let Some(generator) = cli.generator.as_ref() {
let mut cmd = Cli::command();
if generator == &Shell::Zsh || generator == &Shell::Bash || generator == &Shell::Fish {
set_completions(*generator, &mut cmd)?;
cprintln!("<c>{}</c> <y>completions are set", generator);
exit(0)
} else {
print_completions(*generator, &mut cmd);
exit(0)
}
}
Ok(())
/// Generate tab-completion scripts for your shell
Completions {
#[clap(value_enum)]
shell: Shell,
},
}

fn handle_commands(cli: &Cli) -> Result<()> {
Expand Down Expand Up @@ -110,6 +91,14 @@ fn handle_commands(cli: &Cli) -> Result<()> {
Some(Commands::Custom { args }) => {
custom(args)?;
}
Some(Commands::Completions { shell }) => {
clap_complete::generate(
*shell,
&mut Cli::command(),
"wrestic",
&mut std::io::stdout().lock(),
);
}
None => {
selector()?;
}
Expand All @@ -125,7 +114,7 @@ fn handle_repair() -> Result<()> {
let settings = get_config()?;

let selection = if settings.len() > 1 {
let selections: Vec<String> = settings.iter().map(|x| x.name.to_owned()).collect();
let selections: Vec<String> = settings.iter().map(|x| x.name.to_string()).collect();
Select::with_theme(&ColorfulTheme::default())
.with_prompt(cformat!("<y>Where do you want to perform a repair?"))
.default(0)
Expand All @@ -149,7 +138,6 @@ fn main() -> Result<()> {
restic_checker()?;

let cli = Cli::parse();
handle_completions(&cli)?;
handle_commands(&cli)?;

Ok(())
Expand Down
Loading

0 comments on commit f1e03ab

Please sign in to comment.