1- use std:: io;
21use std:: path:: PathBuf ;
32
4- use clap:: { Command , Parser , Subcommand , ValueEnum } ;
5- use clap_complete:: Generator ;
3+ use clap:: { Parser , Subcommand } ;
4+ use clap_complete:: Shell ;
65
76/// A small dotfile manager.
87#[ derive( Debug , Parser , Default , Clone ) ]
98#[ clap( author, version, about, long_about = None ) ]
109pub struct Options {
1110 /// Location of the global configuration
12- #[ arg( short, long, default_value = ".dotter/global.toml" , global = true ) ]
11+ #[ clap(
12+ short,
13+ long,
14+ value_parser,
15+ default_value = ".dotter/global.toml" ,
16+ global = true
17+ ) ]
1318 pub global_config : PathBuf ,
1419
1520 /// Location of the local configuration
16- #[ arg( short, long, default_value = ".dotter/local.toml" , global = true ) ]
21+ #[ clap(
22+ short,
23+ long,
24+ value_parser,
25+ default_value = ".dotter/local.toml" ,
26+ global = true
27+ ) ]
1728 pub local_config : PathBuf ,
1829
1930 /// Location of cache file
20- #[ arg ( long, default_value = ".dotter/cache.toml" ) ]
31+ #[ clap ( long, value_parser , default_value = ".dotter/cache.toml" ) ]
2132 pub cache_file : PathBuf ,
2233
2334 /// Directory to cache into.
24- #[ arg ( long, default_value = ".dotter/cache" ) ]
35+ #[ clap ( long, value_parser , default_value = ".dotter/cache" ) ]
2536 pub cache_directory : PathBuf ,
2637
2738 /// Location of optional pre-deploy hook
28- #[ arg ( long, default_value = ".dotter/pre_deploy.sh" ) ]
39+ #[ clap ( long, value_parser , default_value = ".dotter/pre_deploy.sh" ) ]
2940 pub pre_deploy : PathBuf ,
3041
3142 /// Location of optional post-deploy hook
32- #[ arg ( long, default_value = ".dotter/post_deploy.sh" ) ]
43+ #[ clap ( long, value_parser , default_value = ".dotter/post_deploy.sh" ) ]
3344 pub post_deploy : PathBuf ,
3445
3546 /// Location of optional pre-undeploy hook
36- #[ arg ( long, default_value = ".dotter/pre_undeploy.sh" ) ]
47+ #[ clap ( long, value_parser , default_value = ".dotter/pre_undeploy.sh" ) ]
3748 pub pre_undeploy : PathBuf ,
3849
3950 /// Location of optional post-undeploy hook
40- #[ arg ( long, default_value = ".dotter/post_undeploy.sh" ) ]
51+ #[ clap ( long, value_parser , default_value = ".dotter/post_undeploy.sh" ) ]
4152 pub post_undeploy : PathBuf ,
4253
4354 /// Dry run - don't do anything, only print information.
4455 /// Implies -v at least once
45- #[ arg ( short = 'd' , long = "dry-run" , global = true ) ]
56+ #[ clap ( short = 'd' , long = "dry-run" , global = true ) ]
4657 pub dry_run : bool ,
4758
4859 /// Verbosity level - specify up to 3 times to get more detailed output.
4960 /// Specifying at least once prints the differences between what was before and after Dotter's run
50- #[ arg ( short = 'v' , long = "verbose" , action = clap:: ArgAction :: Count , global = true ) ]
61+ #[ clap ( short = 'v' , long = "verbose" , action = clap:: ArgAction :: Count , global = true ) ]
5162 pub verbosity : u8 ,
5263
5364 /// Quiet - only print errors
54- #[ arg ( short, long, global = true ) ]
65+ #[ clap ( short, long, value_parser , global = true ) ]
5566 pub quiet : bool ,
5667
5768 /// Force - instead of skipping, overwrite target files if their content is unexpected.
5869 /// Overrides --dry-run.
59- #[ arg ( short, long, global = true ) ]
70+ #[ clap ( short, long, value_parser , global = true ) ]
6071 pub force : bool ,
6172
6273 /// Assume "yes" instead of prompting when removing empty directories
63- #[ arg ( short = 'y' , long = "noconfirm" , global = true ) ]
74+ #[ clap ( short = 'y' , long = "noconfirm" , global = true ) ]
6475 pub noconfirm : bool ,
6576
6677 /// Take standard input as an additional files/variables patch, added after evaluating
6778 /// `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch.
68- #[ arg ( short, long, global = true ) ]
79+ #[ clap ( short, long, value_parser , global = true ) ]
6980 pub patch : bool ,
7081
7182 /// Amount of lines that are printed before and after a diff hunk.
72- #[ arg ( long, default_value = "3" ) ]
83+ #[ clap ( long, value_parser , default_value = "3" ) ]
7384 pub diff_context_lines : usize ,
7485
75- #[ command ( subcommand) ]
86+ #[ clap ( subcommand) ]
7687 pub action : Option < Action > ,
7788}
7889
@@ -96,50 +107,12 @@ pub enum Action {
96107
97108 /// Generate shell completions
98109 GenCompletions {
99- /// Set the shell for generating completions [values: bash, elvish, fish, powershell , zsh, nushell ]
110+ /// Set the shell for generating completions [values: bash, elvish, fish, powerShell , zsh]
100111 #[ clap( long, short) ]
101112 shell : Shell ,
102113 } ,
103114}
104115
105- #[ derive( Debug , Clone , Copy , ValueEnum ) ]
106- pub enum Shell {
107- Bash ,
108- Elvish ,
109- Fish ,
110- Powershell ,
111- Zsh ,
112- Nushell ,
113- }
114-
115- impl Generator for Shell {
116- fn file_name ( & self , name : & str ) -> String {
117- use clap_complete:: Shell :: * ;
118- use clap_complete_nushell:: Nushell ;
119- match self {
120- Self :: Bash => Bash . file_name ( name) ,
121- Self :: Elvish => Elvish . file_name ( name) ,
122- Self :: Fish => Fish . file_name ( name) ,
123- Self :: Powershell => PowerShell . file_name ( name) ,
124- Self :: Zsh => Zsh . file_name ( name) ,
125- Self :: Nushell => Nushell . file_name ( name) ,
126- }
127- }
128-
129- fn generate ( & self , cmd : & Command , buf : & mut dyn io:: Write ) {
130- use clap_complete:: Shell :: * ;
131- use clap_complete_nushell:: Nushell ;
132- match self {
133- Self :: Bash => Bash . generate ( cmd, buf) ,
134- Self :: Elvish => Elvish . generate ( cmd, buf) ,
135- Self :: Fish => Fish . generate ( cmd, buf) ,
136- Self :: Powershell => PowerShell . generate ( cmd, buf) ,
137- Self :: Zsh => Zsh . generate ( cmd, buf) ,
138- Self :: Nushell => Nushell . generate ( cmd, buf) ,
139- }
140- }
141- }
142-
143116pub fn get_options ( ) -> Options {
144117 let mut opt = Options :: parse ( ) ;
145118 if opt. dry_run {
0 commit comments