aboutsummaryrefslogtreecommitdiff
path: root/dotup_cli/src/main.rs
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2021-07-08 17:11:46 -0400
committerdiogo464 <[email protected]>2021-07-08 17:11:46 -0400
commited0baec0a3f953c99445f6842dadc5566e89cb75 (patch)
tree9f988c41db34907283dd126dc57d29b3d0792bd9 /dotup_cli/src/main.rs
Initial commit
Diffstat (limited to 'dotup_cli/src/main.rs')
-rw-r--r--dotup_cli/src/main.rs87
1 files changed, 87 insertions, 0 deletions
diff --git a/dotup_cli/src/main.rs b/dotup_cli/src/main.rs
new file mode 100644
index 0000000..6d020e1
--- /dev/null
+++ b/dotup_cli/src/main.rs
@@ -0,0 +1,87 @@
1#![allow(unused)]
2
3pub mod commands;
4pub mod config;
5
6pub use config::Config;
7
8pub mod prelude {
9 pub use super::Config;
10 pub use dotup::{Archive, Depot, DepotConfig, Link, LinkDesc, LinkID};
11}
12
13use clap::{AppSettings, Clap};
14use flexi_logger::Logger;
15use std::{
16 collections::HashMap,
17 iter::FromIterator,
18 path::{Path, PathBuf},
19};
20
21use prelude::*;
22
23const DEFAULT_DEPOT_NAME: &str = "depot.toml";
24
25#[derive(Clap)]
26#[clap(version = "0.1", author = "d464")]
27#[clap(setting = AppSettings::ColoredHelp)]
28struct Opts {
29 /// Path to the depot file.
30 #[clap(long, default_value = DEFAULT_DEPOT_NAME)]
31 depot: PathBuf,
32
33 /// Disable output to the console
34 #[clap(short, long)]
35 quiet: bool,
36
37 /// A level of verbosity, and can be used multiple times
38 ///
39 /// Level 0 - Warnings (Default)
40 /// Level 1 - Info
41 /// Level 2 - Debug
42 /// Level 3 - Trace
43 #[clap(short, long, parse(from_occurrences))]
44 verbose: i32,
45
46 #[clap(subcommand)]
47 subcmd: SubCommand,
48}
49
50#[derive(Clap)]
51enum SubCommand {
52 Init(commands::init::Opts),
53 Link(commands::link::Opts),
54 Unlink(commands::unlink::Opts),
55 Install(commands::install::Opts),
56 Uninstall(commands::uninstall::Opts),
57}
58
59fn main() -> anyhow::Result<()> {
60 let opts = Opts::parse();
61
62 if !opts.quiet {
63 let log_level = match opts.verbose {
64 0 => "warn",
65 1 => "info",
66 2 => "debug",
67 3 | _ => "trace",
68 };
69
70 Logger::try_with_env_or_str(log_level)?
71 .format(flexi_logger::colored_default_format)
72 //.set_palette("196;208;32;198;15".to_string())
73 .start()?;
74 }
75
76 let config = Config {
77 archive_path: opts.depot,
78 };
79
80 match opts.subcmd {
81 SubCommand::Init(opts) => commands::init::main(config, opts),
82 SubCommand::Link(opts) => commands::link::main(config, opts),
83 SubCommand::Unlink(opts) => commands::unlink::main(config, opts),
84 SubCommand::Install(opts) => commands::install::main(config, opts),
85 SubCommand::Uninstall(opts) => commands::uninstall::main(config, opts),
86 }
87}