1pub mod add;
2pub mod admin;
3#[cfg(not(feature = "lt2016_1"))]
4pub mod aliases;
5pub mod annotate;
6pub mod archive;
7pub mod attribute;
8pub mod changes;
9pub mod describe;
10pub mod edit;
11pub mod filelog;
12pub mod print;
13pub mod sync;
14pub mod r#where;
15
16pub use add::Add;
17pub use admin::AdminEntry;
18#[cfg(not(feature = "lt2016_1"))]
19pub use aliases::Aliases;
20pub use annotate::Annotate;
21pub use archive::Archive;
22pub use attribute::Attribute;
23pub use changes::Changes;
24pub use describe::Describe;
25pub use edit::Edit;
26pub use filelog::FileLog;
27pub use print::Print;
28pub use sync::Sync;
29pub use r#where::Where;
30
31use std::{ffi::OsStr, process::Command};
32
33use crate::global::GlobalOpts;
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum LongOutput {
42 Default,
44 Truncated,
46}
47
48impl LongOutput {
49 pub fn as_str(&self) -> &'static str {
51 match self {
52 LongOutput::Default => "-l",
53 LongOutput::Truncated => "-L",
54 }
55 }
56}
57
58#[derive(Debug, Clone, Copy, Default)]
65pub struct Unselected;
66
67impl ExclusiveOption for Unselected {
68 fn inject_args(&self, _: &mut Command) {}
69}
70
71pub trait ExclusiveOption {
84 #[allow(unused_variables)]
85 fn inject_args(&self, command: &mut Command) {}
88}
89
90pub trait SubCommand {
91 fn name(&self) -> &str;
92
93 fn inject_local_args(&self, command: &mut Command);
94
95 fn global_opts(&self) -> Option<&GlobalOpts> {
96 None
97 }
98
99 fn inject_args(&self, command: &mut Command) {
100 if let Some(global_opts) = self.global_opts() {
102 global_opts.setup_args(command);
103 };
104 self.inject_local_args(command.arg(self.name()));
106 }
107
108 fn setup_command<S: AsRef<OsStr>>(&self, bin: S) -> Command {
109 let mut cmd = Command::new(bin);
110
111 self.inject_args(&mut cmd);
112 cmd
113 }
114}
115
116#[cfg(test)]
119pub(crate) fn args_of(command: &Command) -> Vec<String> {
120 command
121 .get_args()
122 .map(|arg| arg.to_string_lossy().into_owned())
123 .collect()
124}