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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use crate::console_utils::ColorOutputPolicy;
use clap::Parser;
use std::path::PathBuf;
use strum_macros::EnumString;
#[derive(Debug, Eq, PartialEq, Clone, Parser)]
#[clap(author, version, about)]
pub struct Args {
/// Print debug output
///
/// This will print debug logs at the trace level. This is useful for debugging and bug reports
/// should contain debug logging info.
#[clap(short, long)]
pub debug: bool,
/// Run a subcommand that doesn't perform a diff. Valid options are: "list",
/// "dump_default_config", and "build_info".
///
/// * "list" lists all of the filetypes/languages that this program was compiled with support
/// for
///
/// * "dump_default_config" will dump the default configuration to stdout
///
/// * "build_info" prints extended build information
#[clap(subcommand)]
pub cmd: Option<Command>,
/// The first file to compare against
///
/// Text that is in this file but is not in the new file is considered a deletion
// #[clap(name = "OLD", parse(from_os_str), required_unless_present = "cmd")]
#[clap(name = "OLD")]
pub old: Option<PathBuf>,
/// The file that the old file is compared against
///
/// Text that is in this file but is not in the old file is considered an addition
// #[clap(name = "NEW", parse(from_os_str), required_unless_present = "cmd")]
#[clap(name = "NEW")]
pub new: Option<PathBuf>,
/// Manually set the file type for the given files
///
/// This will dictate which parser is used with the difftool. You can list all of the valid
/// file type strings with `diffsitter --cmd list`
#[clap(short = 't', long)]
pub file_type: Option<String>,
/// Use the config provided at the given path
///
/// By default, diffsitter attempts to find the config at `$XDG_CONFIG_HOME/diffsitter.json5`.
/// On Windows the app will look in the standard config path.
// #[clap(short, long, env = "DIFFSITTER_CONFIG")]
#[clap(short, long)]
pub config: Option<PathBuf>,
/// Set the color output policy. Valid values are: "auto", "on", "off".
///
/// "auto" will automatically detect whether colors should be applied by trying to determine
/// whether the process is outputting to a TTY. "on" will enable output and "off" will
/// disable color output regardless of whether the process detects a TTY.
#[clap(long = "color", default_value_t)]
pub color_output: ColorOutputPolicy,
/// Ignore any config files and use the default config
///
/// This will cause the app to ignore any configs and all config values will use the their
/// default settings.
#[clap(short, long)]
pub no_config: bool,
/// Specify which renderer tag to use.
///
/// If no option is supplied then this will fall back to the default renderer.
#[clap(short, long)]
pub renderer: Option<String>,
}
/// A wrapper struct for `clap_complete::Shell`.
///
/// We need this wrapper so we can automatically serialize strings using `EnumString` and use the
/// enums as a clap argument.
#[derive(Copy, Clone, EnumString, PartialEq, Eq, Debug)]
#[strum(serialize_all = "snake_case")]
pub enum ShellWrapper {
Bash,
Zsh,
Fish,
Elvish,
#[strum(serialize = "powershell")]
PowerShell,
}
impl Default for ShellWrapper {
fn default() -> Self {
Self::Bash
}
}
impl From<ShellWrapper> for clap_complete::Shell {
fn from(wrapper: ShellWrapper) -> Self {
use clap_complete as cc;
match wrapper {
ShellWrapper::Bash => cc::Shell::Bash,
ShellWrapper::Zsh => cc::Shell::Zsh,
ShellWrapper::Fish => cc::Shell::Fish,
ShellWrapper::Elvish => cc::Shell::Elvish,
ShellWrapper::PowerShell => cc::Shell::PowerShell,
}
}
}
/// Commands related to the configuration
#[derive(Debug, Eq, PartialEq, Clone, Copy, Parser, EnumString)]
#[strum(serialize_all = "snake_case")]
pub enum Command {
/// List the languages that this program was compiled for
List,
/// Dump the default config to stdout
DumpDefaultConfig,
/// Generate shell completion scripts for diffsitter
GenCompletion {
/// The shell to generate completion scripts for.
///
/// This will print the shell completion script to stdout. bash, zsh, and fish are supported.
shell: ShellWrapper,
},
}