dotfiles_processor/
flags.rs

1// Copyright (c) 2021-2022 Miguel Barreto and others
2//
3// Permission is hereby granted, free of charge, to any person obtaining
4// a copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to
8// permit persons to whom the Software is furnished to do so, subject to
9// the following conditions:
10//
11// The above copyright notice and this permission notice shall be
12// included in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22use clap::{Parser, Subcommand, ValueEnum};
23use log::LevelFilter;
24
25#[derive(Parser)]
26#[command(author, version)]
27#[command(name = "dotfiles")]
28#[command(bin_name = "dotfiles")]
29#[command(
30  about = "A simple dotfile manager that can be configured using yaml. See https://github.com/miguelandres/dotfiles-rs"
31)]
32pub struct FlagData {
33  #[command(subcommand)]
34  pub command: Command,
35  #[arg(value_enum, long, default_value_t = LogLevelFilter::Info)]
36  pub log_level_filter: LogLevelFilter,
37}
38
39#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
40pub enum LogLevelFilter {
41  /// A level lower than all log levels.
42  Off,
43  /// Corresponds to the `Error` log level.
44  Error,
45  /// Corresponds to the `Warn` log level.
46  Warn,
47  /// Corresponds to the `Info` log level.
48  Info,
49  /// Corresponds to the `Debug` log level.
50  Debug,
51  /// Corresponds to the `Trace` log level.
52  Trace,
53}
54
55// Exception to this clippy since LogLevelFilter is in a crate I don't own.
56#[allow(clippy::from_over_into)]
57impl Into<LevelFilter> for LogLevelFilter {
58  fn into(self) -> LevelFilter {
59    match self {
60      LogLevelFilter::Off => LevelFilter::Off,
61      LogLevelFilter::Error => LevelFilter::Error,
62      LogLevelFilter::Warn => LevelFilter::Warn,
63      LogLevelFilter::Info => LevelFilter::Info,
64      LogLevelFilter::Debug => LevelFilter::Debug,
65      LogLevelFilter::Trace => LevelFilter::Trace,
66    }
67  }
68}
69
70#[derive(Subcommand)]
71pub enum Command {
72  /// Installs Homebrew on Mac or Linuxbrew on Linux, see <http://brew.sh>
73  #[cfg(any(target_os = "linux", target_os = "macos"))]
74  InstallHomebrew,
75  /// Installs Oh My Zsh! and sets `zsh` as the shell, see <https://ohmyz.sh/>
76  #[cfg(unix)]
77  InstallOhMyZsh {
78    /// Skips running `chsh` to set `zsh` as the shell
79    #[arg(long = "skip-chsh", default_value_t = false)]
80    skip_chsh: bool,
81  },
82  /// Applies the configuration in the file passed as argument.
83  #[command(arg_required_else_help = true)]
84  ApplyConfig {
85    /// Configuration file that describes what to do.
86    file: String,
87    /// Only parse the configuration, do not run it.
88    #[arg(short = 'n', long = "dry-run", default_value_t = false)]
89    dry_run: bool,
90  },
91}