1- mod args;
21pub mod opts;
32pub mod subs;
43
54use crate :: types:: { BitteFind , ClusterHandle } ;
65use anyhow:: { anyhow, Context , Result } ;
76use clap:: { App , ArgMatches , FromArgMatches } ;
8- use clap_complete:: { generate, shells } ;
7+ use clap_complete:: { generate, Generator } ;
98use deploy:: cli as deployCli;
109use deploy:: cli:: Opts as ExtDeployOpts ;
1110use log:: * ;
@@ -27,11 +26,14 @@ pub fn init_log(level: u64) {
2726}
2827
2928pub ( crate ) async fn ssh ( sub : & ArgMatches , cluster : ClusterHandle ) -> Result < ( ) > {
30- let mut args = sub. values_of_lossy ( "args" ) . unwrap_or_default ( ) ;
31- let job: Vec < String > = sub. values_of_t ( "job" ) . unwrap_or_default ( ) ;
32- let delay = Duration :: from_secs ( sub. value_of_t :: < u64 > ( "delay" ) . unwrap_or ( 0 ) ) ;
29+ let mut args: Vec < String > = sub. get_many ( "args" ) . unwrap_or_default ( ) . cloned ( ) . collect ( ) ;
30+ let job: Vec < String > = sub. get_many ( "job" ) . unwrap_or_default ( ) . cloned ( ) . collect ( ) ;
31+ let delay = Duration :: from_secs ( * sub. get_one :: < u64 > ( "delay" ) . unwrap_or ( & 0 ) ) ;
3332
34- let namespace: String = sub. value_of_t ( "namespace" ) . unwrap_or_default ( ) ;
33+ let namespace = sub
34+ . get_one :: < String > ( "namespace" )
35+ . unwrap_or ( & "default" . to_string ( ) )
36+ . to_owned ( ) ;
3537
3638 let ip: IpAddr ;
3739
@@ -76,18 +78,17 @@ pub(crate) async fn ssh(sub: &ArgMatches, cluster: ClusterHandle) -> Result<()>
7678
7779 return Ok ( ( ) ) ;
7880 } else if sub. is_present ( "job" ) {
79- let ( name, group, index) = ( & * job[ 0 ] , & * job[ 1 ] , & job[ 2 ] ) ;
81+ let ( name, group, index) = ( & job[ 0 ] , & job[ 1 ] , & job[ 2 ] ) ;
8082
8183 let nodes = cluster. nodes ;
82- let ( node, alloc) = nodes. find_with_job ( name, group, index, namespace. as_ref ( ) ) ?;
84+ let ( node, alloc) = nodes. find_with_job ( name, group, index, & namespace. clone ( ) ) ?;
85+ ip = node. pub_ip ;
8386 if args. is_empty ( ) {
8487 args. extend ( vec ! [
8588 "-t" . into( ) ,
86- format!( "cd /var/lib/nomad/alloc/{}; bash " , alloc. id) ,
89+ format!( "cd /var/lib/nomad/alloc/{} && exec $SHELL " , alloc. id) ,
8790 ] ) ;
88- }
89-
90- ip = node. pub_ip ;
91+ } ;
9192 } else {
9293 let needle = args. first ( ) ;
9394
@@ -123,8 +124,9 @@ async fn init_ssh(ip: IpAddr, args: Vec<String>, cluster: String) -> Result<()>
123124 flags. push ( user_host) ;
124125
125126 if !args. is_empty ( ) {
126- flags. append ( & mut args. iter ( ) . map ( |string| string. as_str ( ) ) . collect ( ) ) ;
127- }
127+ flags. append ( & mut args. iter ( ) . map ( AsRef :: as_ref) . collect ( ) )
128+ } ;
129+
128130 let ssh_args = flags. into_iter ( ) ;
129131
130132 let mut cmd = Command :: new ( "ssh" ) ;
@@ -290,12 +292,7 @@ async fn info_print(cluster: ClusterHandle, json: bool) -> Result<()> {
290292 Ok ( ( ) )
291293}
292294
293- pub ( crate ) async fn completions ( sub : & ArgMatches , mut app : App < ' _ > ) -> Result < ( ) > {
294- match sub. subcommand ( ) {
295- Some ( ( "bash" , _) ) => generate ( shells:: Bash , & mut app, "bitte" , & mut std:: io:: stdout ( ) ) ,
296- Some ( ( "zsh" , _) ) => generate ( shells:: Zsh , & mut app, "bitte" , & mut std:: io:: stdout ( ) ) ,
297- Some ( ( "fish" , _) ) => generate ( shells:: Fish , & mut app, "bitte" , & mut std:: io:: stdout ( ) ) ,
298- _ => ( ) ,
299- } ;
300- Ok ( ( ) )
295+ pub ( crate ) async fn completions < G : Generator > ( gen : G , mut app : App < ' _ > ) {
296+ let cli = & mut app;
297+ generate ( gen, cli, cli. get_name ( ) . to_string ( ) , & mut std:: io:: stdout ( ) )
301298}
0 commit comments