mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
Warn for missing docs, and add necessary docs
This commit is contained in:
parent
4cfc7b972b
commit
0fdef287c4
@ -1,2 +1,4 @@
|
|||||||
|
//! Archive compression algorithms
|
||||||
|
|
||||||
pub mod tar;
|
pub mod tar;
|
||||||
pub mod zip;
|
pub mod zip;
|
||||||
|
@ -14,6 +14,7 @@ use crate::{
|
|||||||
utils::{self, Bytes, QuestionPolicy},
|
utils::{self, Bytes, QuestionPolicy},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Unpacks the archive given by `archive` into the folder given by `into`.
|
||||||
pub fn unpack_archive(
|
pub fn unpack_archive(
|
||||||
reader: Box<dyn Read>,
|
reader: Box<dyn Read>,
|
||||||
output_folder: &Path,
|
output_folder: &Path,
|
||||||
@ -40,6 +41,7 @@ pub fn unpack_archive(
|
|||||||
Ok(files_unpacked)
|
Ok(files_unpacked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.
|
||||||
pub fn build_archive_from_paths<W>(input_filenames: &[PathBuf], writer: W) -> crate::Result<W>
|
pub fn build_archive_from_paths<W>(input_filenames: &[PathBuf], writer: W) -> crate::Result<W>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
|
@ -70,6 +70,7 @@ where
|
|||||||
Ok(unpacked_files)
|
Ok(unpacked_files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.
|
||||||
pub fn build_archive_from_paths<W>(input_filenames: &[PathBuf], writer: W) -> crate::Result<W>
|
pub fn build_archive_from_paths<W>(input_filenames: &[PathBuf], writer: W) -> crate::Result<W>
|
||||||
where
|
where
|
||||||
W: Write + Seek,
|
W: Write + Seek,
|
||||||
|
@ -10,6 +10,7 @@ use clap::{Parser, ValueHint};
|
|||||||
pub use crate::utils::QuestionPolicy;
|
pub use crate::utils::QuestionPolicy;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
|
/// Command line options
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(version, about)]
|
#[clap(version, about)]
|
||||||
pub struct Opts {
|
pub struct Opts {
|
||||||
@ -21,10 +22,12 @@ pub struct Opts {
|
|||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
pub no: bool,
|
pub no: bool,
|
||||||
|
|
||||||
|
/// Action to take
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
pub cmd: Subcommand,
|
pub cmd: Subcommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Actions to take
|
||||||
#[derive(Parser, PartialEq, Eq, Debug)]
|
#[derive(Parser, PartialEq, Eq, Debug)]
|
||||||
pub enum Subcommand {
|
pub enum Subcommand {
|
||||||
/// Compress files. Alias: c
|
/// Compress files. Alias: c
|
||||||
@ -38,7 +41,7 @@ pub enum Subcommand {
|
|||||||
#[clap(required = true, value_hint = ValueHint::FilePath)]
|
#[clap(required = true, value_hint = ValueHint::FilePath)]
|
||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
},
|
},
|
||||||
/// Compress files. Alias: d
|
/// Decompress files. Alias: d
|
||||||
#[clap(alias = "d")]
|
#[clap(alias = "d")]
|
||||||
Decompress {
|
Decompress {
|
||||||
/// Files to be decompressed
|
/// Files to be decompressed
|
||||||
|
@ -38,6 +38,8 @@ fn represents_several_files(files: &[PathBuf]) -> bool {
|
|||||||
files.iter().any(is_non_empty_dir) || files.len() > 1
|
files.iter().any(is_non_empty_dir) || files.len() > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Entrypoint of ouch, receives cli options and matches Subcommand
|
||||||
|
/// to decide current operation
|
||||||
pub fn run(args: Opts, question_policy: QuestionPolicy) -> crate::Result<()> {
|
pub fn run(args: Opts, question_policy: QuestionPolicy) -> crate::Result<()> {
|
||||||
match args.cmd {
|
match args.cmd {
|
||||||
Subcommand::Compress { files, output: output_path } => {
|
Subcommand::Compress { files, output: output_path } => {
|
||||||
@ -183,6 +185,11 @@ pub fn run(args: Opts, question_policy: QuestionPolicy) -> crate::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compress files into an `output_file`
|
||||||
|
//
|
||||||
|
// files are the list of paths to be compressed: ["dir/file1.txt", "dir/file2.txt"]
|
||||||
|
// formats contains each format necessary for compression, example: [Tar, Gz] (in compression order)
|
||||||
|
// output_file is the resulting compressed file name, example: "compressed.tar.gz"
|
||||||
fn compress_files(files: Vec<PathBuf>, formats: Vec<CompressionFormat>, output_file: fs::File) -> crate::Result<()> {
|
fn compress_files(files: Vec<PathBuf>, formats: Vec<CompressionFormat>, output_file: fs::File) -> crate::Result<()> {
|
||||||
let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file);
|
let file_writer = BufWriter::with_capacity(BUFFER_CAPACITY, output_file);
|
||||||
|
|
||||||
@ -280,6 +287,8 @@ fn compress_files(files: Vec<PathBuf>, formats: Vec<CompressionFormat>, output_f
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decompress a file
|
||||||
|
//
|
||||||
// File at input_file_path is opened for reading, example: "archive.tar.gz"
|
// File at input_file_path is opened for reading, example: "archive.tar.gz"
|
||||||
// formats contains each format necessary for decompression, example: [Gz, Tar] (in decompression order)
|
// formats contains each format necessary for decompression, example: [Gz, Tar] (in decompression order)
|
||||||
// output_folder it's where the file will be decompressed to
|
// output_folder it's where the file will be decompressed to
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
//! TODO: wrap `FinalError` in a variant to keep all `FinalError::display_and_crash()` function
|
//! TODO: wrap `FinalError` in a variant to keep all `FinalError::display_and_crash()` function
|
||||||
//! calls inside of this module.
|
//! calls inside of this module.
|
||||||
|
|
||||||
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
@ -13,6 +15,7 @@ use std::{
|
|||||||
|
|
||||||
use crate::utils::colors::*;
|
use crate::utils::colors::*;
|
||||||
|
|
||||||
|
/// Custom Ouch Errors
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
UnknownExtensionError(String),
|
UnknownExtensionError(String),
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
//! 1. It's required by `main.rs`, or
|
//! 1. It's required by `main.rs`, or
|
||||||
//! 2. It's required by some integration tests at tests/ folder.
|
//! 2. It's required by some integration tests at tests/ folder.
|
||||||
|
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
// Public modules
|
// Public modules
|
||||||
|
pub mod archive;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
|
|
||||||
// Private modules
|
// Private modules
|
||||||
pub mod archive;
|
|
||||||
mod dialogs;
|
mod dialogs;
|
||||||
mod error;
|
mod error;
|
||||||
mod extension;
|
mod extension;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
/// Macro that prints message in INFO mode
|
||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
$crate::macros::_info_helper();
|
$crate::macros::_info_helper();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user