2 use std
::ffi
::OsString
;
3 use std
::path
::PathBuf
;
5 use clap
::{Args, Parser, Subcommand, ValueEnum}
;
7 /// A fictional versioning CLI
8 #[derive(Debug, Parser)] // requires `derive` feature
9 #[command(name = "git")]
10 #[command(about = "A fictional versioning CLI", long_about = None)]
12 #[command(subcommand)]
16 #[derive(Debug, Subcommand)]
19 #[command(arg_required_else_help = true)]
21 /// The remote to clone
24 /// Compare two commits
26 #[arg(value_name = "COMMIT")]
27 base
: Option
<OsString
>,
28 #[arg(value_name = "COMMIT")]
29 head
: Option
<OsString
>,
31 path
: Option
<OsString
>,
34 require_equals
= true,
37 default_value_t
= ColorWhen
::Auto
,
38 default_missing_value
= "always",
44 #[command(arg_required_else_help = true)]
46 /// The remote to target
50 #[command(arg_required_else_help = true)]
53 #[arg(required = true)]
57 #[command(external_subcommand)]
58 External(Vec
<OsString
>),
61 #[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
68 impl std
::fmt
::Display
for ColorWhen
{
69 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
70 self.to_possible_value()
71 .expect("no values are skipped")
77 #[derive(Debug, Args)]
78 #[command(args_conflicts_with_subcommands = true)]
80 #[command(subcommand)]
81 command
: Option
<StashCommands
>,
87 #[derive(Debug, Subcommand)]
90 Pop { stash: Option<String> }
,
91 Apply { stash: Option<String> }
,
94 #[derive(Debug, Args)]
97 message
: Option
<String
>,
101 let args
= Cli
::parse();
104 Commands
::Clone { remote }
=> {
105 println
!("Cloning {}", remote
);
123 .map(|s
| s
.to_str().unwrap())
127 .map(|s
| s
.to_str().unwrap())
128 .unwrap_or("worktree");
129 let path
= path
.as_deref().unwrap_or_else(|| OsStr
::new(""));
131 "Diffing {}..{} {} (color={})",
134 path
.to_string_lossy(),
138 Commands
::Push { remote }
=> {
139 println
!("Pushing to {}", remote
);
141 Commands
::Add { path }
=> {
142 println
!("Adding {:?}", path
);
144 Commands
::Stash(stash
) => {
145 let stash_cmd
= stash
.command
.unwrap_or(StashCommands
::Push(stash
.push
));
147 StashCommands
::Push(push
) => {
148 println
!("Pushing {:?}", push
);
150 StashCommands
::Pop { stash }
=> {
151 println
!("Popping {:?}", stash
);
153 StashCommands
::Apply { stash }
=> {
154 println
!("Applying {:?}", stash
);
158 Commands
::External(args
) => {
159 println
!("Calling out to {:?} with {:?}", &args
[0], &args
[1..]);
163 // Continued program logic goes here...