mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Merge branch 'pr/completions-manpage'
This commit is contained in:
commit
a85eb68a60
20
.github/workflows/build.yml
vendored
20
.github/workflows/build.yml
vendored
@ -104,13 +104,15 @@ jobs:
|
|||||||
- name: Install dependencies for musl libc
|
- name: Install dependencies for musl libc
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install musl-tools
|
sudo apt-get install help2man musl-tools
|
||||||
|
|
||||||
- name: Run cargo build
|
- name: Run cargo build
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
args: --release --target x86_64-unknown-linux-musl
|
args: --release --target x86_64-unknown-linux-musl
|
||||||
|
env:
|
||||||
|
GEN_COMPLETIONS: 1
|
||||||
|
|
||||||
- name: Run cargo test
|
- name: Run cargo test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
@ -118,6 +120,11 @@ jobs:
|
|||||||
command: test
|
command: test
|
||||||
args: --target x86_64-unknown-linux-musl
|
args: --target x86_64-unknown-linux-musl
|
||||||
|
|
||||||
|
- name: Build man page and find completions
|
||||||
|
run: |
|
||||||
|
help2man target/x86_64-unknown-linux-musl/release/ouch > ouch.1
|
||||||
|
cp -r target/x86_64-unknown-linux-musl/release/build/ouch-*/out/completions .
|
||||||
|
|
||||||
- name: Strip binary
|
- name: Strip binary
|
||||||
run: strip target/x86_64-unknown-linux-musl/release/ouch
|
run: strip target/x86_64-unknown-linux-musl/release/ouch
|
||||||
|
|
||||||
@ -127,6 +134,17 @@ jobs:
|
|||||||
name: 'ouch-x86_64-linux-musl'
|
name: 'ouch-x86_64-linux-musl'
|
||||||
path: target/x86_64-unknown-linux-musl/release/ouch
|
path: target/x86_64-unknown-linux-musl/release/ouch
|
||||||
|
|
||||||
|
- name: Upload completions
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: completions
|
||||||
|
path: completions
|
||||||
|
|
||||||
|
- name: Upload man page
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: ouch.1
|
||||||
|
path: ouch.1
|
||||||
|
|
||||||
x86_64_glibc:
|
x86_64_glibc:
|
||||||
name: Ubuntu 20.04 (glibc)
|
name: Ubuntu 20.04 (glibc)
|
||||||
|
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -114,6 +114,15 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -289,6 +298,7 @@ dependencies = [
|
|||||||
"atty",
|
"atty",
|
||||||
"bzip2",
|
"bzip2",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_generate",
|
||||||
"flate2",
|
"flate2",
|
||||||
"fs-err",
|
"fs-err",
|
||||||
"infer",
|
"infer",
|
||||||
|
@ -26,6 +26,10 @@ zip = { version = "0.5.13", default-features = false, features = ["defl
|
|||||||
flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] }
|
flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] }
|
||||||
zstd = { version = "0.9.0", default-features = false, features = ["thin"] }
|
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]
|
[dev-dependencies]
|
||||||
tempfile = "3.2.0"
|
tempfile = "3.2.0"
|
||||||
infer = "0.5.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();
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,8 @@ use walkdir::WalkDir;
|
|||||||
use crate::{
|
use crate::{
|
||||||
error::FinalError,
|
error::FinalError,
|
||||||
info,
|
info,
|
||||||
utils::{self, Bytes, QuestionPolicy},
|
utils::{self, Bytes},
|
||||||
|
QuestionPolicy,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn unpack_archive(
|
pub fn unpack_archive(
|
||||||
|
@ -13,7 +13,8 @@ use zip::{self, read::ZipFile, ZipArchive};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
info,
|
info,
|
||||||
utils::{self, dir_is_empty, strip_cur_dir, Bytes, QuestionPolicy},
|
utils::{self, dir_is_empty, strip_cur_dir, Bytes},
|
||||||
|
QuestionPolicy,
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::utf8::get_invalid_utf8_paths;
|
use self::utf8::get_invalid_utf8_paths;
|
||||||
|
46
src/cli.rs
46
src/cli.rs
@ -5,52 +5,10 @@ use std::{
|
|||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::{Parser, ValueHint};
|
use clap::Parser;
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
pub use crate::utils::QuestionPolicy;
|
use crate::{Error, Opts, QuestionPolicy, Subcommand};
|
||||||
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 = "dir", value_hint = ValueHint::DirPath)]
|
|
||||||
output_dir: Option<PathBuf>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Opts {
|
impl Opts {
|
||||||
/// A helper method that calls `clap::Parser::parse` and then translates relative paths to absolute.
|
/// A helper method that calls `clap::Parser::parse` and then translates relative paths to absolute.
|
||||||
|
@ -12,17 +12,14 @@ use utils::colors;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
archive,
|
archive,
|
||||||
cli::{Opts, Subcommand},
|
|
||||||
error::FinalError,
|
error::FinalError,
|
||||||
extension::{
|
extension::{
|
||||||
self,
|
self,
|
||||||
CompressionFormat::{self, *},
|
CompressionFormat::{self, *},
|
||||||
},
|
},
|
||||||
info,
|
info,
|
||||||
utils::nice_directory_display,
|
utils::{self, dir_is_empty, nice_directory_display, to_utf},
|
||||||
utils::to_utf,
|
Error, Opts, QuestionPolicy, Subcommand,
|
||||||
utils::{self, dir_is_empty, QuestionPolicy},
|
|
||||||
Error,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Used in BufReader and BufWriter to perform less syscalls
|
// Used in BufReader and BufWriter to perform less syscalls
|
||||||
|
@ -5,18 +5,21 @@
|
|||||||
//! 2. It's required by some integration tests at tests/ folder.
|
//! 2. It's required by some integration tests at tests/ folder.
|
||||||
|
|
||||||
// Public modules
|
// Public modules
|
||||||
pub mod cli;
|
pub mod archive;
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
|
|
||||||
// Private modules
|
// Private modules
|
||||||
pub mod archive;
|
mod cli;
|
||||||
mod dialogs;
|
mod dialogs;
|
||||||
mod error;
|
mod error;
|
||||||
mod extension;
|
mod extension;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
mod opts;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
|
pub use opts::{Opts, Subcommand};
|
||||||
|
pub use utils::QuestionPolicy;
|
||||||
|
|
||||||
/// The status code ouch has when an error is encountered
|
/// The status code ouch has when an error is encountered
|
||||||
pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;
|
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() {
|
fn main() {
|
||||||
if let Err(err) = run() {
|
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 = "dir", value_hint = ValueHint::DirPath)]
|
||||||
|
output_dir: Option<PathBuf>,
|
||||||
|
},
|
||||||
|
}
|
@ -7,12 +7,9 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use fs_err as fs;
|
use ouch::{commands::run, Opts, QuestionPolicy, Subcommand};
|
||||||
|
|
||||||
use ouch::{
|
use fs_err as fs;
|
||||||
cli::{Opts, QuestionPolicy, Subcommand},
|
|
||||||
commands::run,
|
|
||||||
};
|
|
||||||
use rand::{rngs::SmallRng, RngCore, SeedableRng};
|
use rand::{rngs::SmallRng, RngCore, SeedableRng};
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use utils::*;
|
use utils::*;
|
||||||
|
@ -6,10 +6,7 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
use ouch::{
|
use ouch::{commands::run, Opts, QuestionPolicy, Subcommand};
|
||||||
cli::{Opts, QuestionPolicy, Subcommand},
|
|
||||||
commands::run,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
|
pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
|
||||||
let dirname = Path::new(filename);
|
let dirname = Path::new(filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user