@@ -44,7 +44,7 @@ use std::string::String as KafkaSslProtocol;
44
44
pub const DEFAULT_USERNAME : & str = "admin" ;
45
45
pub const DEFAULT_PASSWORD : & str = "admin" ;
46
46
47
- #[ derive( Parser ) ]
47
+ #[ derive( Parser , Debug ) ]
48
48
#[ command(
49
49
name = "parseable" ,
50
50
bin_name = "parseable" ,
@@ -73,13 +73,88 @@ Join the community at https://logg.ing/community.
73
73
"# ,
74
74
subcommand_required = true ,
75
75
) ]
76
- pub struct Cli {
76
+ pub enum Cli {
77
+ #[ clap( name = "storage" ) ]
78
+ /// Storage options
79
+ Storage ( StorageOptions ) ,
80
+
81
+ /// Generate shell completions
82
+ #[ clap( name = "completions" ) ]
83
+ Completion ( CommandCompletionOptions ) ,
84
+ }
85
+
86
+ // taken generously from https://github.com/jj-vcs/jj/blob/be32d4e3efbb9a51deadcc63635a5fb1526d0d6c/cli/src/commands/util/completion.rs#L23C1-L47C36
87
+ // Using an explicit `doc` attribute prevents rustfmt from mangling the list
88
+ // formatting without disabling rustfmt for the entire struct.
89
+ #[ doc = r#"Print a command-line-completion script
90
+
91
+ Apply it by running one of these:
92
+
93
+ - Bash: `source <(pb util completion bash)`
94
+ - Fish: `pb util completion fish | source`
95
+ - Nushell:
96
+ ```nu
97
+ pb util completion nushell | save "completions-pb.nu"
98
+ use "completions-pb.nu" * # Or `source "completions-pb.nu"`
99
+ ```
100
+ - Zsh:
101
+ ```shell
102
+ autoload -U compinit
103
+ compinit
104
+ source <(pb util completion zsh)
105
+ ```
106
+ "# ]
107
+
108
+ #[ derive( clap:: Args , Debug ) ]
109
+ #[ command( verbatim_doc_comment) ]
110
+ pub struct CommandCompletionOptions {
111
+ pub shell : Option < ShellCompletion > ,
112
+ }
113
+
114
+ /// Available shell completions
115
+ #[ derive( clap:: ValueEnum , Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
116
+ pub enum ShellCompletion {
117
+ Bash ,
118
+ Elvish ,
119
+ Fish ,
120
+ // Nushell,
121
+ PowerShell ,
122
+ Zsh ,
123
+ }
124
+
125
+ impl ShellCompletion {
126
+ pub fn generate ( & self , cmd : & mut clap:: Command ) -> Vec < u8 > {
127
+ use clap_complete:: generate;
128
+ use clap_complete:: Shell ;
129
+ // use clap_complete_nushell::Nushell;
130
+
131
+ let mut buf = Vec :: new ( ) ;
132
+
133
+ let bin_name = "pb" ;
134
+
135
+ match self {
136
+ Self :: Bash => generate ( Shell :: Bash , cmd, bin_name, & mut buf) ,
137
+ Self :: Elvish => generate ( Shell :: Elvish , cmd, bin_name, & mut buf) ,
138
+ Self :: Fish => generate ( Shell :: Fish , cmd, bin_name, & mut buf) ,
139
+ // Self::Nushell => generate(Nushell, cmd, bin_name, &mut buf),
140
+ Self :: PowerShell => generate ( Shell :: PowerShell , cmd, bin_name, & mut buf) ,
141
+ Self :: Zsh => generate ( Shell :: Zsh , cmd, bin_name, & mut buf) ,
142
+ }
143
+
144
+ buf
145
+ }
146
+ }
147
+
148
+ // todo remove caution
149
+ #[ derive( clap:: Args , Debug ) ]
150
+ pub struct StorageOptions {
77
151
#[ command( subcommand) ]
78
- pub storage : StorageOptions ,
152
+ pub storage : StorageOptionsEnum ,
79
153
}
80
154
81
- #[ derive( Parser ) ]
82
- pub enum StorageOptions {
155
+ // todo remove caution
156
+ #[ derive( clap:: Subcommand , Debug ) ]
157
+ pub enum StorageOptionsEnum {
83
158
#[ command( name = "local-store" ) ]
84
159
Local ( LocalStoreArgs ) ,
85
160
@@ -90,23 +165,23 @@ pub enum StorageOptions {
90
165
Blob ( BlobStoreArgs ) ,
91
166
}
92
167
93
- #[ derive( Parser ) ]
168
+ #[ derive( Parser , Debug ) ]
94
169
pub struct LocalStoreArgs {
95
170
#[ command( flatten) ]
96
171
pub options : Options ,
97
172
#[ command( flatten) ]
98
173
pub storage : FSConfig ,
99
174
}
100
175
101
- #[ derive( Parser ) ]
176
+ #[ derive( Parser , Debug ) ]
102
177
pub struct S3StoreArgs {
103
178
#[ command( flatten) ]
104
179
pub options : Options ,
105
180
#[ command( flatten) ]
106
181
pub storage : S3Config ,
107
182
}
108
183
109
- #[ derive( Parser ) ]
184
+ #[ derive( Parser , Debug ) ]
110
185
pub struct BlobStoreArgs {
111
186
#[ command( flatten) ]
112
187
pub options : Options ,
0 commit comments