1+ use std:: io;
12use std:: path:: PathBuf ;
23
3- use clap:: { Parser , Subcommand } ;
4- use clap_complete:: Shell ;
4+ use clap:: { Command , Parser , Subcommand , ValueEnum } ;
5+ use clap_complete:: Generator ;
56
67/// A small dotfile manager.
78#[ derive( Debug , Parser , Default , Clone ) ]
89#[ clap( author, version, about, long_about = None ) ]
910pub struct Options {
1011 /// Location of the global configuration
11- #[ clap(
12- short,
13- long,
14- value_parser,
15- default_value = ".dotter/global.toml" ,
16- global = true
17- ) ]
12+ #[ arg( short, long, default_value = ".dotter/global.toml" , global = true ) ]
1813 pub global_config : PathBuf ,
1914
2015 /// Location of the local configuration
21- #[ clap(
22- short,
23- long,
24- value_parser,
25- default_value = ".dotter/local.toml" ,
26- global = true
27- ) ]
16+ #[ arg( short, long, default_value = ".dotter/local.toml" , global = true ) ]
2817 pub local_config : PathBuf ,
2918
3019 /// Location of cache file
31- #[ clap ( long, value_parser , default_value = ".dotter/cache.toml" ) ]
20+ #[ arg ( long, default_value = ".dotter/cache.toml" ) ]
3221 pub cache_file : PathBuf ,
3322
3423 /// Directory to cache into.
35- #[ clap ( long, value_parser , default_value = ".dotter/cache" ) ]
24+ #[ arg ( long, default_value = ".dotter/cache" ) ]
3625 pub cache_directory : PathBuf ,
3726
3827 /// Location of optional pre-deploy hook
39- #[ clap ( long, value_parser , default_value = ".dotter/pre_deploy.sh" ) ]
28+ #[ arg ( long, default_value = ".dotter/pre_deploy.sh" ) ]
4029 pub pre_deploy : PathBuf ,
4130
4231 /// Location of optional post-deploy hook
43- #[ clap ( long, value_parser , default_value = ".dotter/post_deploy.sh" ) ]
32+ #[ arg ( long, default_value = ".dotter/post_deploy.sh" ) ]
4433 pub post_deploy : PathBuf ,
4534
4635 /// Location of optional pre-undeploy hook
47- #[ clap ( long, value_parser , default_value = ".dotter/pre_undeploy.sh" ) ]
36+ #[ arg ( long, default_value = ".dotter/pre_undeploy.sh" ) ]
4837 pub pre_undeploy : PathBuf ,
4938
5039 /// Location of optional post-undeploy hook
51- #[ clap ( long, value_parser , default_value = ".dotter/post_undeploy.sh" ) ]
40+ #[ arg ( long, default_value = ".dotter/post_undeploy.sh" ) ]
5241 pub post_undeploy : PathBuf ,
5342
5443 /// Dry run - don't do anything, only print information.
5544 /// Implies -v at least once
56- #[ clap ( short = 'd' , long = "dry-run" , global = true ) ]
45+ #[ arg ( short = 'd' , long = "dry-run" , global = true ) ]
5746 pub dry_run : bool ,
5847
5948 /// Verbosity level - specify up to 3 times to get more detailed output.
6049 /// Specifying at least once prints the differences between what was before and after Dotter's run
61- #[ clap ( short = 'v' , long = "verbose" , action = clap:: ArgAction :: Count , global = true ) ]
50+ #[ arg ( short = 'v' , long = "verbose" , action = clap:: ArgAction :: Count , global = true ) ]
6251 pub verbosity : u8 ,
6352
6453 /// Quiet - only print errors
65- #[ clap ( short, long, value_parser , global = true ) ]
54+ #[ arg ( short, long, global = true ) ]
6655 pub quiet : bool ,
6756
6857 /// Force - instead of skipping, overwrite target files if their content is unexpected.
6958 /// Overrides --dry-run.
70- #[ clap ( short, long, value_parser , global = true ) ]
59+ #[ arg ( short, long, global = true ) ]
7160 pub force : bool ,
7261
7362 /// Assume "yes" instead of prompting when removing empty directories
74- #[ clap ( short = 'y' , long = "noconfirm" , global = true ) ]
63+ #[ arg ( short = 'y' , long = "noconfirm" , global = true ) ]
7564 pub noconfirm : bool ,
7665
7766 /// Take standard input as an additional files/variables patch, added after evaluating
7867 /// `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch.
79- #[ clap ( short, long, value_parser , global = true ) ]
68+ #[ arg ( short, long, global = true ) ]
8069 pub patch : bool ,
8170
8271 /// Amount of lines that are printed before and after a diff hunk.
83- #[ clap ( long, value_parser , default_value = "3" ) ]
72+ #[ arg ( long, default_value = "3" ) ]
8473 pub diff_context_lines : usize ,
8574
86- #[ clap ( subcommand) ]
75+ #[ command ( subcommand) ]
8776 pub action : Option < Action > ,
8877}
8978
@@ -107,12 +96,50 @@ pub enum Action {
10796
10897 /// Generate shell completions
10998 GenCompletions {
110- /// Set the shell for generating completions [values: bash, elvish, fish, powerShell , zsh]
99+ /// Set the shell for generating completions [values: bash, elvish, fish, powershell , zsh, nushell ]
111100 #[ clap( long, short) ]
112101 shell : Shell ,
113102 } ,
114103}
115104
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+
116143pub fn get_options ( ) -> Options {
117144 let mut opt = Options :: parse ( ) ;
118145 if opt. dry_run {
0 commit comments