File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -673,6 +673,12 @@ pub enum Command {
673673 #[ arg( value_enum) ]
674674 shell : Shell ,
675675 } ,
676+ /// Generates standard shell tab-completion scripts for tv's various subcommands.
677+ #[ clap( name = "completions" ) ]
678+ Completions {
679+ #[ arg( value_enum) ]
680+ shell : Shell ,
681+ } ,
676682 /// Downloads the latest collection of channel prototypes from github
677683 /// and saves them to the local configuration directory.
678684 UpdateChannels {
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ use television::{
2323 utils:: {
2424 shell:: {
2525 Shell , completion_script, render_autocomplete_script_template,
26+ render_clap_autocomplete,
2627 } ,
2728 stdin:: is_readable_stdin,
2829 } ,
@@ -146,6 +147,18 @@ pub fn handle_subcommand(
146147 let _ = writeln ! ( stdout( ) . lock( ) , "{script}" ) ;
147148 exit ( 0 ) ;
148149 }
150+ Command :: Completions { shell } => {
151+ let target_shell = Shell :: from ( shell) ;
152+ if let Some ( script) = render_clap_autocomplete ( target_shell) {
153+ let _ = writeln ! ( stdout( ) . lock( ) , "{script}" ) ;
154+ } else {
155+ eprintln ! (
156+ "Shell completions are not supported for {target_shell}"
157+ ) ;
158+ exit ( 1 ) ;
159+ }
160+ exit ( 0 ) ;
161+ }
149162 Command :: UpdateChannels { force } => {
150163 update_local_channels ( force) ?;
151164 exit ( 0 ) ;
Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ pub fn render_autocomplete_script_template(
238238 Ok ( clap_autocomplete + & script)
239239}
240240
241- fn render_clap_autocomplete ( shell : Shell ) -> Option < String > {
241+ pub fn render_clap_autocomplete ( shell : Shell ) -> Option < String > {
242242 // Clap autocomplete
243243 let mut clap_autocomplete = vec ! [ ] ;
244244 let mut cmd = Cli :: command ( ) ;
You can’t perform that action at this time.
0 commit comments