Warn for missing docs, and add necessary docs

This commit is contained in:
Gabriel Simonetto 2021-10-27 00:08:00 -03:00
parent 4cfc7b972b
commit 0fdef287c4
8 changed files with 25 additions and 2 deletions

View File

@ -1,2 +1,4 @@
//! Archive compression algorithms
pub mod tar;
pub mod zip;

View File

@ -14,6 +14,7 @@ use crate::{
utils::{self, Bytes, QuestionPolicy},
};
/// Unpacks the archive given by `archive` into the folder given by `into`.
pub fn unpack_archive(
reader: Box<dyn Read>,
output_folder: &Path,
@ -40,6 +41,7 @@ pub fn unpack_archive(
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>
where
W: Write,

View File

@ -70,6 +70,7 @@ where
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>
where
W: Write + Seek,

View File

@ -10,6 +10,7 @@ use clap::{Parser, ValueHint};
pub use crate::utils::QuestionPolicy;
use crate::Error;
/// Command line options
#[derive(Parser, Debug)]
#[clap(version, about)]
pub struct Opts {
@ -21,10 +22,12 @@ pub struct Opts {
#[clap(short, long)]
pub no: bool,
/// Action to take
#[clap(subcommand)]
pub cmd: Subcommand,
}
/// Actions to take
#[derive(Parser, PartialEq, Eq, Debug)]
pub enum Subcommand {
/// Compress files. Alias: c
@ -38,7 +41,7 @@ pub enum Subcommand {
#[clap(required = true, value_hint = ValueHint::FilePath)]
output: PathBuf,
},
/// Compress files. Alias: d
/// Decompress files. Alias: d
#[clap(alias = "d")]
Decompress {
/// Files to be decompressed

View File

@ -38,6 +38,8 @@ fn represents_several_files(files: &[PathBuf]) -> bool {
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<()> {
match args.cmd {
Subcommand::Compress { files, output: output_path } => {
@ -183,6 +185,11 @@ pub fn run(args: Opts, question_policy: QuestionPolicy) -> crate::Result<()> {
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<()> {
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(())
}
// Decompress a file
//
// 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)
// output_folder it's where the file will be decompressed to

View File

@ -6,6 +6,8 @@
//! TODO: wrap `FinalError` in a variant to keep all `FinalError::display_and_crash()` function
//! calls inside of this module.
#![allow(missing_docs)]
use std::{
fmt::{self, Display},
path::{Path, PathBuf},
@ -13,6 +15,7 @@ use std::{
use crate::utils::colors::*;
/// Custom Ouch Errors
#[derive(Debug, PartialEq)]
pub enum Error {
UnknownExtensionError(String),

View File

@ -4,12 +4,14 @@
//! 1. It's required by `main.rs`, or
//! 2. It's required by some integration tests at tests/ folder.
#![warn(missing_docs)]
// Public modules
pub mod archive;
pub mod cli;
pub mod commands;
// Private modules
pub mod archive;
mod dialogs;
mod error;
mod extension;

View File

@ -1,4 +1,5 @@
#[macro_export]
/// Macro that prints message in INFO mode
macro_rules! info {
($($arg:tt)*) => {
$crate::macros::_info_helper();