mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
generate completions
This commit is contained in:
parent
a46fa1fb38
commit
7efac2e55d
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -114,6 +114,15 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_generate"
|
||||
version = "3.0.0-beta.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "097ab5db1c3417442270cd57c8dd39f6c3114d3ce09d595f9efddbb1fcfaa799"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.1"
|
||||
@ -283,6 +292,7 @@ dependencies = [
|
||||
"atty",
|
||||
"bzip2",
|
||||
"clap",
|
||||
"clap_generate",
|
||||
"flate2",
|
||||
"infer",
|
||||
"libc",
|
||||
|
@ -25,6 +25,10 @@ zip = { version = "0.5.13", default-features = false, features = ["defl
|
||||
flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] }
|
||||
zstd = { version = "0.9.0", default-features = false, features = ["thin"] }
|
||||
|
||||
[build-dependencies]
|
||||
clap = "=3.0.0-beta.5"
|
||||
clap_generate = "=3.0.0-beta.5"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.2.0"
|
||||
infer = "0.5.0"
|
||||
|
22
build.rs
Normal file
22
build.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use clap::{ArgEnum, IntoApp};
|
||||
use clap_generate::{generate_to, Shell};
|
||||
|
||||
use std::{env, fs::create_dir_all, path::Path};
|
||||
|
||||
include!("src/opts.rs");
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-env-changed=GEN_COMPLETIONS");
|
||||
|
||||
if env::var_os("GEN_COMPLETIONS") != Some("1".into()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let out = &Path::new(&env::var_os("OUT_DIR").unwrap()).join("completions");
|
||||
create_dir_all(out).unwrap();
|
||||
let app = &mut Opts::into_app();
|
||||
|
||||
for shell in Shell::value_variants() {
|
||||
generate_to(*shell, app, "ouch", out).unwrap();
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ use zip::{self, read::ZipFile, ZipArchive};
|
||||
|
||||
use crate::{
|
||||
info,
|
||||
utils::{self, dir_is_empty,strip_cur_dir, Bytes},
|
||||
utils::{self, dir_is_empty, strip_cur_dir, Bytes},
|
||||
};
|
||||
|
||||
use self::utf8::get_invalid_utf8_paths;
|
||||
|
45
src/cli.rs
45
src/cli.rs
@ -5,50 +5,9 @@ use std::{
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
use clap::{Parser, ValueHint};
|
||||
use clap::Parser;
|
||||
|
||||
use crate::Error;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version, about)]
|
||||
pub struct Opts {
|
||||
/// Skip overwrite questions positively.
|
||||
#[clap(short, long, conflicts_with = "no")]
|
||||
pub yes: bool,
|
||||
|
||||
/// Skip overwrite questions negatively.
|
||||
#[clap(short, long)]
|
||||
pub no: bool,
|
||||
|
||||
#[clap(subcommand)]
|
||||
pub cmd: Subcommand,
|
||||
}
|
||||
|
||||
#[derive(Parser, PartialEq, Eq, Debug)]
|
||||
pub enum Subcommand {
|
||||
/// Compress files. Alias: c
|
||||
#[clap(alias = "c")]
|
||||
Compress {
|
||||
/// Files to be compressed
|
||||
#[clap(required = true, min_values = 1)]
|
||||
files: Vec<PathBuf>,
|
||||
|
||||
/// The resulting file. Its extensions specify how the files will be compressed and they need to be supported
|
||||
#[clap(required = true, value_hint = ValueHint::FilePath)]
|
||||
output: PathBuf,
|
||||
},
|
||||
/// Compress files. Alias: d
|
||||
#[clap(alias = "d")]
|
||||
Decompress {
|
||||
/// Files to be decompressed
|
||||
#[clap(required = true, min_values = 1)]
|
||||
files: Vec<PathBuf>,
|
||||
|
||||
/// Decompress files in a directory other than the current
|
||||
#[clap(short, long, value_hint = ValueHint::DirPath)]
|
||||
output: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
use crate::{Error, Opts, Subcommand};
|
||||
|
||||
impl Opts {
|
||||
/// A helper method that calls `clap::Parser::parse` and then translates relative paths to absolute.
|
||||
|
@ -12,7 +12,6 @@ use utils::colors;
|
||||
|
||||
use crate::{
|
||||
archive,
|
||||
cli::{Opts, Subcommand},
|
||||
error::FinalError,
|
||||
extension::{
|
||||
self,
|
||||
@ -22,7 +21,7 @@ use crate::{
|
||||
utils::nice_directory_display,
|
||||
utils::to_utf,
|
||||
utils::{self, dir_is_empty},
|
||||
Error,
|
||||
Error, Opts, Subcommand,
|
||||
};
|
||||
|
||||
// Used in BufReader and BufWriter to perform less syscalls
|
||||
|
@ -5,18 +5,20 @@
|
||||
//! 2. It's required by some integration tests at tests/ folder.
|
||||
|
||||
// Public modules
|
||||
pub mod cli;
|
||||
pub mod archive;
|
||||
pub mod commands;
|
||||
|
||||
// Private modules
|
||||
pub mod archive;
|
||||
mod cli;
|
||||
mod dialogs;
|
||||
mod error;
|
||||
mod extension;
|
||||
mod macros;
|
||||
mod opts;
|
||||
mod utils;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
pub use opts::{Opts, Subcommand};
|
||||
|
||||
/// The status code ouch has when an error is encountered
|
||||
pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use ouch::{cli::Opts, commands, Result};
|
||||
use ouch::{commands, Opts, Result};
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = run() {
|
||||
|
44
src/opts.rs
Normal file
44
src/opts.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use clap::{Parser, ValueHint};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version, about)]
|
||||
pub struct Opts {
|
||||
/// Skip overwrite questions positively.
|
||||
#[clap(short, long, conflicts_with = "no")]
|
||||
pub yes: bool,
|
||||
|
||||
/// Skip overwrite questions negatively.
|
||||
#[clap(short, long)]
|
||||
pub no: bool,
|
||||
|
||||
#[clap(subcommand)]
|
||||
pub cmd: Subcommand,
|
||||
}
|
||||
|
||||
#[derive(Parser, PartialEq, Eq, Debug)]
|
||||
pub enum Subcommand {
|
||||
/// Compress files. Alias: c
|
||||
#[clap(alias = "c")]
|
||||
Compress {
|
||||
/// Files to be compressed
|
||||
#[clap(required = true, min_values = 1)]
|
||||
files: Vec<PathBuf>,
|
||||
|
||||
/// The resulting file. Its extensions specify how the files will be compressed and they need to be supported
|
||||
#[clap(required = true, value_hint = ValueHint::FilePath)]
|
||||
output: PathBuf,
|
||||
},
|
||||
/// Compress files. Alias: d
|
||||
#[clap(alias = "d")]
|
||||
Decompress {
|
||||
/// Files to be decompressed
|
||||
#[clap(required = true, min_values = 1)]
|
||||
files: Vec<PathBuf>,
|
||||
|
||||
/// Decompress files in a directory other than the current
|
||||
#[clap(short, long, value_hint = ValueHint::DirPath)]
|
||||
output: Option<PathBuf>,
|
||||
},
|
||||
}
|
@ -7,10 +7,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use ouch::{
|
||||
cli::{Opts, Subcommand},
|
||||
commands::run,
|
||||
};
|
||||
use ouch::{commands::run, Opts, Subcommand};
|
||||
use rand::{rngs::SmallRng, RngCore, SeedableRng};
|
||||
use tempfile::NamedTempFile;
|
||||
use utils::*;
|
||||
|
@ -7,10 +7,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use ouch::{
|
||||
cli::{Opts, Subcommand},
|
||||
commands::run,
|
||||
};
|
||||
use ouch::{commands::run, Opts, Subcommand};
|
||||
|
||||
pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
|
||||
let dirname = Path::new(filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user