@@ -2,6 +2,7 @@ pub mod aboutme;
22pub mod apps;
33pub mod authstatus;
44pub mod commit;
5+ pub mod status;
56pub mod init;
67pub mod login;
78pub mod logs;
@@ -35,7 +36,7 @@ macro_rules! handle_result {
3536 }
3637 } ;
3738}
38- use crate :: entities:: FetchError ;
39+ use crate :: entities:: { FetchError , app :: App } ;
3940#[ tracing:: instrument]
4041pub fn expect_token ( ) -> String {
4142 if crate :: auth:: validate_token ( ) {
@@ -99,15 +100,43 @@ mod tests {
99100 assert_eq ! ( super :: format_warn( "Some warnings" ) , out)
100101 }
101102}
102- pub fn ask_for_app ( token : String , action : & str , teams : bool ) -> Result < u128 , FetchError > {
103+
104+ pub fn ask_for_app ( token : String , action : & str , teams : bool ) -> Result < App , FetchError > {
105+ let mut apps = if teams {
106+ crate :: entities:: app:: App :: fetch_foreign_apps ( token)
107+ } else {
108+ crate :: entities:: app:: App :: fetch_all ( token)
109+ } ?;
110+ match apps. len ( ) {
111+ 0 => {
112+ err ( "You don't have any apps!" ) ;
113+ std:: process:: exit ( 1 ) ;
114+ } ,
115+ 1 => Ok ( apps. remove ( 0 ) ) ,
116+ _ => {
117+ let options = apps
118+ . iter ( )
119+ . map ( |app| format ! ( "{}: ({}) {}" , app. name, app. lang, app. id) )
120+ . collect :: < Vec < _ > > ( ) ;
121+ let chosen_opt = Select :: with_theme ( & ColorfulTheme :: default ( ) )
122+ . items ( & options)
123+ . with_prompt ( format ! ( "Which app you want to {}?" , action) )
124+ . interact ( )
125+ . unwrap ( ) ;
126+ Ok ( apps. remove ( chosen_opt) )
127+ }
128+ }
129+ }
130+
131+ pub fn ask_for_app_id ( token : String , action : & str , teams : bool ) -> Result < u128 , FetchError > {
103132 let apps = if teams {
104133 crate :: entities:: app:: App :: fetch_foreign_apps ( token)
105134 } else {
106135 crate :: entities:: app:: App :: fetch_all ( token)
107136 } ?;
108137 match apps. len ( ) {
109138 0 => {
110- format_err ( "You don't have any apps!" ) ;
139+ err ( "You don't have any apps!" ) ;
111140 std:: process:: exit ( 1 ) ;
112141 } ,
113142 1 => Ok ( apps[ 0 ] . id . parse ( ) . unwrap ( ) ) ,
0 commit comments