@@ -44,7 +44,7 @@ use std::string::String as KafkaSslProtocol;
4444pub const DEFAULT_USERNAME : & str = "admin" ;
4545pub const DEFAULT_PASSWORD : & str = "admin" ;
4646
47- #[ derive( Parser ) ]
47+ #[ derive( Parser , Debug ) ]
4848#[ command(
4949 name = "parseable" ,
5050 bin_name = "parseable" ,
@@ -73,13 +73,88 @@ Join the community at https://logg.ing/community.
7373 "# ,
7474 subcommand_required = true ,
7575) ]
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 {
77151 #[ command( subcommand) ]
78- pub storage : StorageOptions ,
152+ pub storage : StorageOptionsEnum ,
79153}
80154
81- #[ derive( Parser ) ]
82- pub enum StorageOptions {
155+ // todo remove caution
156+ #[ derive( clap:: Subcommand , Debug ) ]
157+ pub enum StorageOptionsEnum {
83158 #[ command( name = "local-store" ) ]
84159 Local ( LocalStoreArgs ) ,
85160
@@ -90,23 +165,23 @@ pub enum StorageOptions {
90165 Blob ( BlobStoreArgs ) ,
91166}
92167
93- #[ derive( Parser ) ]
168+ #[ derive( Parser , Debug ) ]
94169pub struct LocalStoreArgs {
95170 #[ command( flatten) ]
96171 pub options : Options ,
97172 #[ command( flatten) ]
98173 pub storage : FSConfig ,
99174}
100175
101- #[ derive( Parser ) ]
176+ #[ derive( Parser , Debug ) ]
102177pub struct S3StoreArgs {
103178 #[ command( flatten) ]
104179 pub options : Options ,
105180 #[ command( flatten) ]
106181 pub storage : S3Config ,
107182}
108183
109- #[ derive( Parser ) ]
184+ #[ derive( Parser , Debug ) ]
110185pub struct BlobStoreArgs {
111186 #[ command( flatten) ]
112187 pub options : Options ,
0 commit comments