22mod git;
33mod remotes;
44
5- use clap:: { crate_authors, crate_version, load_yaml , App , AppSettings , ArgMatches } ;
5+ use clap:: { crate_authors, crate_version, App , AppSettings , ArgMatches , YamlLoader } ;
66use colored:: * ;
77use git2:: ErrorCode ;
8+ use lazy_static:: lazy_static;
89use log:: { debug, error, info, trace} ;
910use std:: io:: { self , stdin, stdout, Cursor , Write } ;
10- use std:: { env, process} ;
11+ use std:: { env, include_str , process} ;
1112use tabwriter:: TabWriter ;
13+ use yaml_rust:: Yaml ;
14+
15+ lazy_static ! {
16+ static ref APP_CFG : Yaml = {
17+ YamlLoader :: load_from_str( include_str!( "../cli-flags.yml" ) )
18+ . expect( "Failed to load CLI config" )
19+ . pop( )
20+ . unwrap( )
21+ } ;
22+ }
1223
1324/// Get the remote url
1425fn get_remote_url ( remote_name : & str ) -> String {
@@ -171,6 +182,7 @@ fn generate_completion(app: &mut App, shell_name: &str) {
171182 print ! ( "{}" , & output) ;
172183}
173184
185+ /// Get the name of the remote to use for the operation
174186fn get_remote_name ( matches : & ArgMatches ) -> String {
175187 let default_remote_name = match git:: get_project_config ( "defaultremote" ) {
176188 Some ( remote_name) => remote_name,
@@ -207,8 +219,9 @@ fn get_remote_name(matches: &ArgMatches) -> String {
207219 )
208220}
209221
210- fn build_cli ( cfg : & yaml_rust:: Yaml ) -> App {
211- App :: from_yaml ( & cfg)
222+ /// Get the Clap app for CLI matching et al.
223+ fn build_cli < ' a > ( ) -> App < ' a , ' a > {
224+ App :: from_yaml ( & APP_CFG )
212225 . version ( crate_version ! ( ) )
213226 . author ( crate_authors ! ( "\n " ) )
214227 . setting ( AppSettings :: ArgsNegateSubcommands )
@@ -222,8 +235,8 @@ fn main() {
222235 . parse_filters ( & env:: var ( "REQ_LOG" ) . unwrap_or_default ( ) )
223236 . try_init ( ) ;
224237
225- let cfg = load_yaml ! ( "../cli-flags.yml" ) ;
226- let app = build_cli ( & cfg ) ;
238+ let mut app = build_cli ( ) ;
239+
227240 let matches = app. get_matches ( ) ;
228241
229242 if let Some ( project_id) = matches. value_of ( "NEW_PROJECT_ID" ) {
@@ -239,7 +252,7 @@ fn main() {
239252 } else if let Some ( remote_name) = matches. value_of ( "NEW_DEFAULT_REMOTE" ) {
240253 set_default_remote ( remote_name) ;
241254 } else if let Some ( shell_name) = matches. value_of ( "GENERATE_COMPLETIONS" ) {
242- let mut app = build_cli ( & cfg ) ;
255+ app = build_cli ( ) ;
243256 generate_completion ( & mut app, & shell_name) ;
244257 } else {
245258 checkout_mr (
0 commit comments