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
use anyhow::Result;
use clap::Parser;
use fern::colors::{Color, ColoredLevelConfig};
use std::path::PathBuf;
/// Setup logging interface
pub fn setup_logger(verbose: u8) -> Result<()> {
// Create colors for level
let colors = ColoredLevelConfig::new()
.error(Color::Red)
.warn(Color::Yellow)
.info(Color::Cyan)
.debug(Color::Magenta)
.trace(Color::White);
// Define Ferm logger
fern::Dispatch::new()
.format(move |out, message, record| {
out.finish(format_args!(
"[{}]\t{}",
colors.color(record.level()),
message
));
})
.level(match verbose {
0 => log::LevelFilter::Warn,
1 => log::LevelFilter::Info,
2 => log::LevelFilter::Debug,
3.. => log::LevelFilter::Trace,
})
.chain(std::io::stdout())
.apply()?;
Ok(())
}
/// Input parameters for the program
#[derive(Debug, Parser)]
#[command(version, author, disable_help_flag = true, trailing_var_arg = true)]
pub struct Params {
/// Print Help
#[arg(short, long)]
pub help: bool,
/// Print **Lua Definition File** `wefter.d.lua` directly to terminal
#[arg(long)]
pub meta: bool,
/// Enable Info(**v**), Debug(**vv**) or Trace(**vvv**) messages
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
/// Override project root *(Current working directory by default)*
#[arg(long)]
pub root: Option<PathBuf>,
/// Folder to lookup for local profiles
#[arg(short = 'd', long, default_value = ".wefter")]
pub local_resources: PathBuf,
/// List available profiles *(Profiles are read from resource directories)*
#[arg(long)]
pub profiles: bool,
/// List command structure for the current profile
#[arg(long, short = 'l')]
pub commands: bool,
/// Profile to use, if not present use **'auto.lua'**
#[arg(short, long)]
pub profile: Option<String>,
/// Trailing parameters, this ones are sent directly to the profile configuration
pub trailing: Vec<String>,
}