feat: add --list-formats command, support auto-generated man pages
Release / check-release (push) Successful in 16s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m43s
CI / Build Linux (push) Successful in 2m21s
Release / check-release (push) Successful in 16s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m43s
CI / Build Linux (push) Successful in 2m21s
This commit is contained in:
1 parent
f58f73194e
commit
a372937854
4 files changed
+70
-11
No files matched your search
+8
-4
@@ -15,11 +15,15 @@
|
||||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version = VERSION, about = "A file converter program.", long_about = None)]
|
||||
#[command(about = "A file converter program.", long_about = None)]
|
||||
pub struct Args {
|
||||
#[arg(
|
||||
long,
|
||||
help = "List all supported formats.",
|
||||
exclusive = true
|
||||
)]
|
||||
pub list_formats: bool,
|
||||
#[arg(
|
||||
short = 'v',
|
||||
long,
|
||||
@@ -58,7 +62,7 @@ pub struct Args {
|
||||
pub priority: String,
|
||||
|
||||
#[arg(help = "The input file path.")]
|
||||
pub input_path: String,
|
||||
pub input_path: Option<String>,
|
||||
|
||||
#[arg(help = "The output file path (optional).")]
|
||||
pub output_path: Option<String>,
|
||||
|
||||
+36
-6
@@ -21,13 +21,18 @@ pub mod runner;
|
||||
include!(concat!(env!("OUT_DIR"), "/plugins_gen.rs"));
|
||||
|
||||
use args::Args;
|
||||
use clap::Parser;
|
||||
use clap::{Parser, CommandFactory, FromArgMatches};
|
||||
use std::fs;
|
||||
use std::io::{self, IsTerminal, Write};
|
||||
use std::process;
|
||||
|
||||
pub const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
let mut command = Args::command();
|
||||
command = command.version(VERSION);
|
||||
let matches = command.get_matches();
|
||||
let args = Args::from_arg_matches(&matches).expect("Failed to parse arguments");
|
||||
|
||||
let level_filter = if args.quiet {
|
||||
tracing_subscriber::filter::LevelFilter::OFF
|
||||
@@ -39,8 +44,35 @@ fn main() {
|
||||
.with_max_level(level_filter)
|
||||
.init();
|
||||
|
||||
let plugins = get_plugins();
|
||||
|
||||
if args.list_formats {
|
||||
let mut formats: std::collections::HashSet<&str> = std::collections::HashSet::new();
|
||||
for p in &plugins {
|
||||
formats.extend(p.from_formats());
|
||||
formats.extend(p.to_formats());
|
||||
}
|
||||
let mut formats_vec: Vec<_> = formats.into_iter().collect();
|
||||
formats_vec.sort();
|
||||
|
||||
println!("Supported Formats:");
|
||||
for chunk in formats_vec.chunks(6) {
|
||||
let row = chunk.iter().map(|s| format!("{:<10}", s)).collect::<Vec<_>>().join(" ");
|
||||
println!(" {}", row);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let input_path = match &args.input_path {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
tracing::error!("Input file path is required unless --list-formats is used.");
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Read input file
|
||||
let input_bytes = match fs::read(&args.input_path) {
|
||||
let input_bytes = match fs::read(input_path) {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
tracing::error!("Error reading input file: {}", e);
|
||||
@@ -48,9 +80,7 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
let plugins = get_plugins();
|
||||
|
||||
let from_format = match identifier::identify_format(&args.input_path, &plugins) {
|
||||
let from_format = match identifier::identify_format(input_path, &plugins) {
|
||||
Some(f) => f,
|
||||
None => {
|
||||
tracing::error!("Unknown input format.");
|
||||
|
||||
Reference in new issue
Block a user