From 0fdef287c4c191a137f23d6195e28a5dfe276f2a Mon Sep 17 00:00:00 2001 From: Gabriel Simonetto Date: Wed, 27 Oct 2021 00:08:00 -0300 Subject: [PATCH] Warn for missing docs, and add necessary docs --- src/archive/mod.rs | 2 ++ src/archive/tar.rs | 2 ++ src/archive/zip.rs | 1 + src/cli.rs | 5 ++++- src/commands.rs | 9 +++++++++ src/error.rs | 3 +++ src/lib.rs | 4 +++- src/macros.rs | 1 + 8 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/archive/mod.rs b/src/archive/mod.rs index be3f336..e02b432 100644 --- a/src/archive/mod.rs +++ b/src/archive/mod.rs @@ -1,2 +1,4 @@ +//! Archive compression algorithms + pub mod tar; pub mod zip; diff --git a/src/archive/tar.rs b/src/archive/tar.rs index bb52d7e..9720243 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -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, 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(input_filenames: &[PathBuf], writer: W) -> crate::Result where W: Write, diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 87d1a17..ca1855c 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -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(input_filenames: &[PathBuf], writer: W) -> crate::Result where W: Write + Seek, diff --git a/src/cli.rs b/src/cli.rs index 1ec281b..e725e44 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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 diff --git a/src/commands.rs b/src/commands.rs index 2543c67..49e7d0c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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, formats: Vec, 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, formats: Vec, 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 diff --git a/src/error.rs b/src/error.rs index a8dd654..114f580 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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), diff --git a/src/lib.rs b/src/lib.rs index 9a1a795..3edee45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/macros.rs b/src/macros.rs index 76877fa..c570831 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,4 +1,5 @@ #[macro_export] +/// Macro that prints message in INFO mode macro_rules! info { ($($arg:tt)*) => { $crate::macros::_info_helper();