gemrendr 0.3.1

Turns Gemtext into idiomatic HTML
Documentation
//! gemrendr   Turns Gemtext into idiomatic HTML.
//! Copyright (C) 2025  AverageHelper
//!
//! This program is free software: you can redistribute it and/or modify
//! it under the terms of the GNU General Public License as published by
//! the Free Software Foundation, either version 3 of the License, or
//! (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program.  If not, see <https://www.gnu.org/licenses/>.

use ::clap::{Parser, ValueHint::FilePath};
use ::gemrendr::{CopyButtonStyle, EmptyLineTag};
use ::std::path::PathBuf;

#[derive(Parser)]
#[command(version, about, long_about = None)]
pub(crate) struct Args {
	/// Print the project license
	#[arg(long)]
	pub license: bool,

	/// The file where HTML should be written.
	///
	/// Use `-` to indicate that HTML should be sent to stdout.
	#[arg(short = 'O', long, value_hint = FilePath, required_unless_present("license"))]
	pub out_file: Option<PathBuf>,

	/// The file where Gemtext should be read.
	///
	/// Use `-` to indicate that Gemtext should be read from stdin.
	#[clap(required_unless_present("license"))]
	pub in_file: Option<PathBuf>,

	/// Whether and how to draw a Copy Text button on preformatted blocks.
	#[arg(short = 'c', long, value_enum, default_value_t)]
	pub copy_button_style: CopyButtonStyle,

	/// The tag to use for empty lines.
	#[arg(short = 'e', long, value_enum, default_value_t)]
	pub empty_line_tag: EmptyLineTag,

	/// Whether to omit the generated-by notice comment in output.
	///
	/// By default, gemrendr prepends output with an HTML comment that
	/// points readers to gemrendr's source code. This extra output might
	/// be too verbose for some use cases. Adding `--no-preamble` to
	/// the command causes this preamble to be omitted.
	#[arg(short = 'n', long, default_value_t)]
	pub no_preamble: bool,
}

// MARK: - Tests

#[cfg(test)]
mod tests {
	use super::*;
	use crate::constants::PKG_NAME;

	#[test]
	fn test_parse() {
		let args = [PKG_NAME, "-O", "-", "-"]; // stdin->stdout

		match Args::try_parse_from(args) {
			Err(err) => panic!("{err}"),
			Ok(args) => {
				assert_eq!(args.license, false);
				assert_eq!(args.out_file, Some(PathBuf::from("-")));
				assert_eq!(args.in_file, Some(PathBuf::from("-")));
			}
		}
	}
}