-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rs
86 lines (77 loc) · 2.13 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// #![deny(warnings)]
mod convert;
mod diff;
mod merge;
mod set_meta;
mod show;
mod split;
mod utils;
#[macro_use]
extern crate clap;
use clap::Parser;
fn main() {
use Commands::*;
match Cli::parse().command {
Show(args) => args.show(),
Split(args) => args.split(),
Merge(args) => args.merge(),
Convert(args) => args.convert(),
Diff(args) => args.diff(),
SetMeta(args) => args.set_meta(),
}
}
/// gguf-utils is a command-line tool for working with gguf files.
#[derive(Parser)]
#[clap(version)]
struct Cli {
#[clap(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Show the contents of gguf files
Show(show::ShowArgs),
/// Split gguf files into shards
Split(split::SplitArgs),
/// Merge shards into a single gguf file
Merge(merge::MergeArgs),
/// Convert gguf files to different format
Convert(convert::ConvertArgs),
/// Diff two gguf files
Diff(diff::DiffArgs),
/// Set metadata of gguf files
SetMeta(set_meta::SetMetaArgs),
}
#[derive(Args, Default)]
struct LogArgs {
/// Log level, may be "off", "trace", "debug", "info" or "error".
#[clap(long)]
log: Option<String>,
}
impl LogArgs {
fn init(self) {
use log::LevelFilter;
use simple_logger::SimpleLogger;
use time::UtcOffset;
let level = self
.log
.and_then(|level| match level.to_lowercase().as_str() {
"off" | "none" => Some(LevelFilter::Off),
"all" | "trace" => Some(LevelFilter::Trace),
"debug" => Some(LevelFilter::Debug),
"info" => Some(LevelFilter::Info),
"error" => Some(LevelFilter::Error),
_ => None,
})
.unwrap_or(LevelFilter::Warn);
const EAST8: UtcOffset = match UtcOffset::from_hms(8, 0, 0) {
Ok(it) => it,
Err(_) => unreachable!(),
};
SimpleLogger::new()
.with_level(level)
.with_utc_offset(UtcOffset::current_local_offset().unwrap_or(EAST8))
.init()
.unwrap();
}
}