aboutsummaryrefslogtreecommitdiff
path: root/dotup_cli/src/main.rs
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2022-02-08 09:21:12 +0000
committerdiogo464 <[email protected]>2022-02-08 09:21:12 +0000
commit92b05a877eb772985d2f4fc9cd198ca642b69b6a (patch)
tree4a2edc173b8809e929e4abc47899ae9c6d956684 /dotup_cli/src/main.rs
parent0992c36733f58750da93921041424fd09f0158ed (diff)
removed old code
Diffstat (limited to 'dotup_cli/src/main.rs')
-rw-r--r--dotup_cli/src/main.rs111
1 files changed, 0 insertions, 111 deletions
diff --git a/dotup_cli/src/main.rs b/dotup_cli/src/main.rs
deleted file mode 100644
index 0d730da..0000000
--- a/dotup_cli/src/main.rs
+++ /dev/null
@@ -1,111 +0,0 @@
1#![allow(unused)]
2
3pub mod commands;
4pub mod config;
5pub mod utils;
6
7pub use config::Config;
8
9pub mod prelude {
10 pub use super::{utils, Config};
11 pub use clap::{AppSettings, Parser};
12 pub use dotup::{Archive, Depot, DepotConfig, Link, LinkCreateParams, LinkID};
13}
14
15use clap::{AppSettings, Parser};
16use flexi_logger::Logger;
17use std::{
18 collections::HashMap,
19 iter::FromIterator,
20 path::{Path, PathBuf},
21};
22
23use prelude::*;
24
25#[derive(Parser)]
26struct Opts {
27 /// Path to the depot file.
28 ///
29 /// By default it will try to find a file named "depot.toml" in the current directory or any of
30 /// the parent directories.
31 #[clap(long)]
32 depot: Option<PathBuf>,
33
34 /// Disable output to the console
35 #[clap(short, long)]
36 quiet: bool,
37
38 /// A level of verbosity, and can be used multiple times
39 ///
40 /// Level 1 - Info
41 ///
42 /// Level 2 - Debug
43 ///
44 /// Level 3 - Trace
45 #[clap(short, long, parse(from_occurrences))]
46 verbose: i32,
47
48 /// The location where links will be installed to.
49 /// Defaults to the home directory.
50 #[clap(short, long)]
51 install_path: Option<PathBuf>,
52
53 #[clap(subcommand)]
54 subcmd: SubCommand,
55}
56
57#[derive(Parser)]
58enum SubCommand {
59 Init(commands::init::Opts),
60 Link(commands::link::Opts),
61 Mv(commands::mv::Opts),
62 Status(commands::status::Opts),
63 Unlink(commands::unlink::Opts),
64 Install(commands::install::Opts),
65 Uninstall(commands::uninstall::Opts),
66}
67
68fn main() -> anyhow::Result<()> {
69 let opts = Opts::parse();
70
71 if !opts.quiet {
72 let log_level = match opts.verbose {
73 0 => "warn",
74 1 => "info",
75 2 => "debug",
76 _ => "trace",
77 };
78
79 Logger::try_with_env_or_str(log_level)?
80 .format(flexi_logger::colored_default_format)
81 .set_palette("196;208;32;198;15".to_string())
82 .start()?;
83 }
84
85 let archive_path = match opts.depot {
86 Some(path) => path,
87 None => utils::find_archive_path()?,
88 };
89 let install_path = match opts.install_path {
90 Some(path) => path,
91 None => utils::home_directory()?,
92 };
93 let working_path = std::env::current_dir().expect("Failed to obtain current working directory");
94 log::debug!("Archive path : {}", archive_path.display());
95
96 let config = Config {
97 archive_path,
98 install_path,
99 working_path,
100 };
101
102 match opts.subcmd {
103 SubCommand::Init(opts) => commands::init::main(config, opts),
104 SubCommand::Link(opts) => commands::link::main(config, opts),
105 SubCommand::Mv(opts) => commands::mv::main(config, opts),
106 SubCommand::Status(opts) => commands::status::main(config, opts),
107 SubCommand::Unlink(opts) => commands::unlink::main(config, opts),
108 SubCommand::Install(opts) => commands::install::main(config, opts),
109 SubCommand::Uninstall(opts) => commands::uninstall::main(config, opts),
110 }
111}